2016-08-15 66 views
1

如何創建imageview/imagebutton像google play一樣提示?
請參見下面的圖像Android imageview longpress hint

enter image description here

它顯示下面的時候,我們對搜索圖標長按搜索圖標敬酒,請指教

+0

這不是你需要爲之工作的東西,它會在你放置時自動向你顯示建議工具欄中的任何菜單項。您必須在菜單項標籤中添加此行。 'android:title =「搜索Google Play」' –

+0

查看@KrishnaJ答案就是這樣。 –

回答

1

您可以使用工具欄菜單,在菜單文件:android:title="Search Google Play"這個屬性。

例如:

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    tools:context="com.example.drawer.EditTransaction" > 

<item 
    android:id="@+id/action_delete" 
    android:orderInCategory="100" 
    android:title="Delete" 
    android:icon="@drawable/ic_action_delete" 
    app:showAsAction="always"/> 

</menu> 

您可以將工具欄和菜單是這樣的:

toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 
    this.toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white100); 
    getSupportActionBar().setTitle("Edit Transaction"); 

點擊事件爲此而努力是菜單做的事:

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.edit_transaction, menu); 
    return true; 
} 


@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    switch (item.getItemId()) { 
    case R.id.action_delete: 
     exitConfirmDialog(); 
     break; 
    default: 
     break; 
    } 
    return super.onOptionsItemSelected(item); 
} 
+0

謝謝,我該如何實現工具欄菜單? 我正在使用沒有操作欄的工具欄,並且正如我所知,當我們使用NoActionbar主題時,我們無法使用工具欄 – Ali