이 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로 사라졌다 다음 버튼을 사용하면 웹보기의 가시성을 설정해야 클릭에 가시성을 설정할 수 있습니다 자바 코드
xml 파일에서 webview의 가시성을 'GONE (으)로 설정하고 버튼 클릭시 표시하도록 시도 했습니까? – pooja