0

이 WebView를 버튼의 onClick 기능에 추가하려고하는데, 버튼을 클릭하기 전에 WebView가 항상 존재합니다. 클릭했을 때만 WebView 이 나타나기를 원합니다. 누구든지 단추를 클릭하면 WebView 작업을 가져올 필요가 어떤 코드를 말할 수 있습니다.ANDROID : 버튼을 클릭하면 WebView가 생성됩니다.

<WebView 
    android:id="@+id/webView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" /> 

XML 코드

private SectionsPagerAdapter mSectionsPagerAdapter; 

private ViewPager mViewPager; 
protected Button mButton; 
private WebView webview; 
ViewPager mHolder; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_app_home); 

    Button mButton = (Button) findViewById(R.id.infobutton); 
    mButton.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 

      webview = (WebView) findViewById(R.id.webView); 
      webview.getSettings().setJavaScriptEnabled(true); 

      String chtml = "<html>"+ 
        "<style> div{height:50%; width:70%; background-color:#aaa;} body div:nth-child(2){height:20%; margin:20px; width:30%; background-color:#222;} h1{ color:red; font-size:24px;}</style>" + 
        "<body><h1>hello, webview</h1> <div></div> <div></div> </body></html>"; 
      webview.loadData(chtml, "text/html", "UTF-8"); 

     } 
    }); 

당신이 XML로 사라졌다 다음 버튼을 사용하면 웹보기의 가시성을 설정해야 클릭에 가시성을 설정할 수 있습니다 자바 코드

+0

xml 파일에서 webview의 가시성을 'GONE (으)로 설정하고 버튼 클릭시 표시하도록 시도 했습니까? – pooja

답변

0

마지막으로 WebView를 API 데이터에 추가하는 방법을 발견했습니다

eventDesctibtion = (WebView) findViewById(R.id.corporateDescription); 
     WebSettings settings= eventDesctibtion.getSettings(); 
     settings.setDefaultFontSize(11); 

로드 데이터를 볼 수 있도록 버튼

protected WebView eventDesctibtion; 

할당 생성 버튼

eventDesctibtion.loadData(object.getString("description"), "text/html; charset=utf-8", "UTF-8"); 
1

보이지 않게.

1
<WebView 
    android:id="@+id/web" 
    android:visibility="invisible" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_gravity="center" /> 

안드로이드를 추가하는 우리가 레이아웃 잊지 마세요이합니다

자바의 가시성 = "보이지 않는"버튼 내부

public class MainActivity extends AppCompatActivity { 

WebView web; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.fgfg); 
    Button bt = (Button)findViewById(R.id.button); 
    web =(WebView)findViewById(R.id.web); 
    bt.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      web.setVisibility(View.VISIBLE); 
      startWebView("http://www.youtube.com"); 
     } 
    }); 
} 

클릭

+0

webview.setVisibility (View.VISIBLE)를 추가 할 때 추가했습니다. 내부 자바 코드 애플 리케이션 내에서 –

+0

나는 위의 code.it의 작동 –

+0

감사하지만, 링크를 사용자 정의 웹 페이지를 추가해야합니다 .. 내가 설정을 추가하면 응용 프로그램 구조체를 추가합니다. –

관련 문제