检测主按钮的点击事件中的Android(应用程序启动器图标) [英] Detect the click event of home button in android (application launcher icon)
本文介绍了检测主按钮的点击事件中的Android(应用程序启动器图标)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何识别在android的应用程序启动器图标点击事件?我需要去主屏幕,一旦用户点击这个图标。例如,假设这是清单文件:
How to identify the click event in the application launcher icon in android? I need to go to home screen once the user click on this icon. For example, assume this is the manifest file:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
..........
在主要活动使用以下code段
在的onCreate()
actionBar=getActionBar();
actionBar.setHomeButtonEnabled(true);
在应用程序图标点击可以。我不'有什么方法来检测这个click事件。这是可能在android系统的事情。任何建议这样做吗?
the application icon is click-able .I don't' have any way to detect the click event of this. Is this possible to do in android. Any suggestion to do that?
推荐答案
您必须覆盖 onOptionsItemSelected()
。试试这个:
You have to override onOptionsItemSelected()
. Try this:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
// do what you want to be done on home button click event
return true;
default:
return super.onOptionsItemSelected(item);
}
}
其他细节检查Android开发者:用户界面操作栏一>
这篇关于检测主按钮的点击事件中的Android(应用程序启动器图标)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文