【发布时间】:2015-10-04 06:34:17
【问题描述】:
长按工具栏项后有什么方法可以隐藏吐司吗?
android ToolBar 图标或长按图像按钮显示吐司。
【问题讨论】:
-
你想说什么?显示吐司,当点击工具栏时应该消失还是什么?
-
仔细阅读问题。问题很明显。谢谢
标签: android android-toolbar android-menu
长按工具栏项后有什么方法可以隐藏吐司吗?
android ToolBar 图标或长按图像按钮显示吐司。
【问题讨论】:
标签: android android-toolbar android-menu
好的。我的问题解决了。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu, menu);
new Handler().post(new Runnable() {
@Override
public void run() {
final View v = findViewById(R.id.action_settings);
if (v != null) {
v.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
});
}
}
});
new Handler().post(new Runnable() {
@Override
public void run() {
final View v = findViewById(R.id.action_search);
if (v != null) {
v.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return false;
}
});
}
}
});
return true;
}
你可以拥有Toolbar的可点击项目:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_search) {
Toast.makeText(context,"action_search",Toast.LENGTH_SHORT).show();
return true;
}else if (id == R.id.action_settings) {
Toast.makeText(context,"action_settings",Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
【讨论】:
Handler来设置OnLongClickListener?