2012-10-09 133 views
2

在android webview中,可以在webview的默認上下文操作欄菜單中添加菜單項。當某些webview頁面內容菜單項應顯示在共享菜單項列表中。你想知道關於操縱上下文菜單的ActionBar如何將菜單項添加到webview的上下文操作欄菜單中

enter image description here

+2

嗨馬特,我是一個android.i的新手試圖找到一些教程,但沒有找到任何。有辦法添加新的上下文操作欄,但我需要添加到現有one.Any幫助這將很有意思 –

+0

其實有一種方法,請參考第一個答案http://stackoverflow.com/questions/22336903/override-onlongtouch-in-a-webview-but-keep-text-selection#2 – Defuera

回答

1

一切都是here。您可以簡單地爲上下文動作模式外觀充氣菜單。

@Override 
public boolean onCreateActionMode(ActionMode mode, Menu menu) { 
    // Inflate a menu resource providing context menu items 
    MenuInflater inflater = mode.getMenuInflater(); 
    inflater.inflate(R.menu.context_menu, menu); 
    return true; 
} 
0

如果你正在尋找的教程,這裏有一些資源可以使用:

https://developer.android.com/guide/topics/ui/menus.html#context-menu

http://wptrafficanalyzer.in/blog/creating-a-contextual-menu-bar-contextual-action-mode-for-a-single-view-in-android/

http://mobile.tutsplus.com/tutorials/android/android-sdk-context-menus/

基本上,你可以創建一個佈局和膨脹它點擊你的按鈕:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/menu_layout" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:padding="10dip" > 

<TextView 
    android:id="@+id/menuItem1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:text="@string/menu1" /> 

<TextView 
    android:id="@+id/menuItem2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:text="@string/menu2" /> 
<TextView 
    android:id="@+id/menuItem3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dip" 
    android:text="@string/menu3" /> 
</LinearLayout> 

,並在您showPopup()方法,你可以這樣做:

public void showPopup(View v) { 
    LayoutInflater inflater = (LayoutInflater) MainActivity.this 
       .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     PopupWindow pw = new PopupWindow(inflater.inflate(
       R.layout.container, null, false), 400, 500, true); 
     pw.showAtLocation(findViewById(R.id.menu_layout), Gravity.CENTER, 0, 
       0); 
} 
2

在Android的WebView是否有可能在的WebView默認上下文操作欄菜單中添加一個菜單項。

不,對不起。很少有Android小部件可以讓你爲他們的動作模式做出貢獻 - EditText可以,這是我能想到的唯一一個。

+0

TextView也有效。 – Prateek

相關問題