如何为类似Google Play的imageview / imagebutton创建提示?
请看下图

android - Android imageview长按提示-LMLPHP

当我们长按搜索图标时,它会在搜索图标下方显示一个吐司,请注意

最佳答案

您可以使用工具栏菜单,并在菜单文件: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);
}

关于android - Android imageview长按提示,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38951046/

10-12 00:30
查看更多