如何在android中识别应用程序启动器图标中的点击事件?用户单击此图标后,我需要转到主屏幕。例如,假设这是 list 文件:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
..........
在 onCreate()
内的 main activity
中使用以下代码段
actionBar=getActionBar();
actionBar.setHomeButtonEnabled(true);
应用程序图标是可点击的。我没有任何方法来检测它的点击事件。这可以在 android 中执行吗?有什么建议吗?
最佳答案
您必须覆盖 onOptionsItemSelected()
。试试这个:
@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 开发人员的其他详细信息检查:"User Interface. Action Bar" .
关于android - 检测android中主页按钮的点击事件(应用程序启动器图标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22754733/