0
我有兩個ImageButtons,onClick將導致webview。但我不能添加第二個Imagebutton。我不知道如何添加它。誰能幫我這個?我有兩個ImageButtons,onClick將導致webview。但我不能添加第二個Imagebutton
我的主要活動
public class main extends AppCompatActivity {
ImageButton imageButton1;
ImageButton imageButton2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
final ImageButton flipkart = (ImageButton) findViewById(R.id.imagebutton1);
final ImageButton amazon = (ImageButton) findViewById(R.id.imagebutton2);
flipkart.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(main.this, MainActivity.class);
intent.setData(Uri.parse("http://www.amazon.in"));
startActivity(intent);
}
});
主要XML文件
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/amazon"
android:layout_marginTop="17dp"
android:id="@+id/imagebutton1"
android:layout_marginStart="11dp"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/flipkart"
android:id="@+id/imagebutton2"
android:layout_marginStart="31dp"
android:layout_alignTop="@+id/imagebutton1"
android:layout_toEndOf="@+id/imagebutton1" />
我的WebView
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView htmlWebView = (WebView) findViewById(R.id.webView);
htmlWebView.setWebViewClient(new CustomWebViewClient());
WebSettings webSetting = htmlWebView.getSettings();
webSetting.setJavaScriptEnabled(true);
webSetting.setDisplayZoomControls(true);
htmlWebView.loadUrl("url");
}
class CustomWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
的WebView XML
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView">
</WebView>