2016-07-25 91 views
0

我已經創建了圖像按鈕作爲標籤菜單,我想顯示此標籤下的webview。圖像按鈕的作品,但我的目的地顯示在新窗口。我是Android的初學者。如果你們知道,請幫助我。如何顯示圖像按鈕下的網頁視圖?

這是我的MainActivity.java。

public void onCreate(Bundle savedInstanceState) { 
    final Context context = this; 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    Intent intent = new Intent(context, WebViewActivity.class); 
    startActivity(intent); 
    /*onClick Button Function*/ 
    // addListeneHomeButton(); 
    // addListenerLoginButton(); 
    // button = (Button) findViewById(R.id.imageButtonHomeSelector); 
    // button.setFocusable(true); 
    //button.setFocusableInTouchMode(true); 

    button.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View arg0) { 
      Intent intent = new Intent(context, WebViewActivity.class); 

      startActivity(intent); 
     } 

    }); 
+0

爲什麼你'onCreate'把'intent'。你的任務是什麼? –

回答

1

對於下按鈕,您可以創建自己的XML設計和使用編程方式見下文如何WebViewin您的設計使用製作的WebView。

XML設計。的WebView

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <Button 
     android:id="@+id/buttonUrl" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Go to http://www.google.com" /> 

    <WebView 
    android:id="@+id/webView1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 

</LinearLayout> 

Java代碼:

+0

謝謝蘇海爾。但是我想把這三個按鈕放在水平位置。 – Myat

+0

@Myat添加按鈕作爲你的設計沒有問題我剛剛添加了webview代碼,你可以根據你的需要和設計修改,如果有幫助,請打勾標記。 –

相關問題