Android imageview longpress提示

时间:2016-08-15 07:35:18

标签: android

如何为google play等图像视图/图像按钮创建提示? 请看下面的图片

enter image description here

当我们长时间点击搜索图标时,它会在搜索图标下面显示一个吐司,请提供建议

2 个答案:

答案 0 :(得分:2)

对于ImageView,您可以使用:

android:tooltipText="This is tip"

它仅适用于android 8.0及更高版本(API级别26及更高版本)

答案 1 :(得分: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);
}
相关问题