screen1.xml에 4 개의 이미지 버튼이 있습니다. screen3.xml에서 webview를 정의했습니다. ImageButton1 또는 다른 버튼을 클릭하면 (웹보기의) 예상 URL이 screen3.xml에로드됩니다.Android : 새 화면에서 webview를 여는 방법
나는이 작업을 시도했지만 forceclose 오류가 발생합니다. 그러나 screen1.xml에 정의 된 webview를 사용하여이 작업을 시도하면 작동합니다. 그러나 문제는 Image Buttons이며 webview는 같은 페이지에 나타나며 겹쳐서 끔찍하게 보입니다!
새 화면에서 webview를 열어주세요.
현재로서는 addView를이 용도로 사용할 수 있습니까?
public class click extends Activity
{
private WebView webView;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
webView = (WebView) findViewById(R.id.web_view);
ImageButton i1 = (ImageButton) findViewById(R.id.imagebutton1);
ImageButton i2 = (ImageButton) findViewById(R.id.imagebutton2);
ImageButton i3 = (ImageButton) findViewById(R.id.imagebutton3);
ImageButton i4 = (ImageButton) findViewById(R.id.imagebutton4);
}
private void openBrowser1()
{
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("myurl");
}
public void myClickHandler1(View view)
{
openBrowser1();
}
Screen1.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
<ImageButton android:id="@+id/imagebutton1" android:clickable="true" android:onClick="myClickHandler1"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="21dip"
android:layout_y="61dip" ></ImageButton>
<ImageButton android:id="@+id/imagebutton2" android:clickable="true" android:onClick="myClickHandler2"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="171dip"
android:layout_y="61dip" ></ImageButton>
<ImageButton android:id="@+id/imagebutton3" android:clickable="true" android:onClick="myClickHandler3"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="21dip"
android:layout_y="241dip" ></ImageButton>
<ImageButton android:id="@+id/imagebutton4" android:clickable="true" android:onClick="myClickHandler4"
android:layout_width="130dip" android:background="@null" android:layout_height="130dip" android:layout_x="171dip"
android:layout_y="241dip" ></ImageButton>
</AbsoluteLayout>
screen3.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<WebView
android:id="@+id/web_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
</AbsoluteLayout>
답장을 보내 주셔서 감사합니다. Jorgesys가 말했듯이, 나는 내 코드에서 무엇이 잘못되었는지 찾아 내려고 노력했다. 나는이 줄을 "webView = (WebView) findViewById (R.id.web_view);"를 openbrowser1() 메소드에 추가해야한다. 또한 screen1.xml에서 "webview"특성을 제거해야합니다. 이것은 스크린 3에서 webview를로드하려고했을 때 FC를 얻는 이유입니다. – emmarbe