即使使用setHomeButtonEnabled(true)应用程序图标也无法在Android 14中单击

时间:2013-08-07 11:35:24

标签: android android-actionbar android-4.0-ice-cream-sandwich

我的代码:(已更新) 我在这里添加了onCreateOptionsMenu和onOptionsItemSelected方法:

  ActionBar actionBar = getActionBar();
  actionBar.setHomeButtonEnabled(true);
  actionBar.setDisplayHomeAsUpEnabled(true);
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.login, menu);
    return true;
    }
   @Override
   public boolean onOptionsItemSelected(MenuItem item) {
   // Handle item selection
   switch (item.getItemId()) {
       case R.id.action_createInvoice:
           startActivity(new Intent("com.domain.Activity1"));
           return true;

       default:
           return super.onOptionsItemSelected(item);
       }
   }

我的清单文件:

    <uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="17" />

    <activity android:label="@string/activity" android:name=".Activity"
        android:parentActivityName="com.some.activity">
         <meta-data
        android:name="android.support.PARENT_ACTIVITY"
        android:value="com.some.activity" />
        <intent-filter>
            <action android:name="com.this.activity" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

使用此设置,应用程序图标在Android 14模拟器中无法点击

2 个答案:

答案 0 :(得分:11)

覆盖onOptionsItemSelected():

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        // do your stuff here, eg: finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

获取Android id的列表:http://developer.android.com/reference/android/R.id.html#home

答案 1 :(得分:0)

试试这对我有用

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id==android.R.id.home)
    {
        NavUtils.navigateUpFromSameTask(this);
    }
    return super.onOptionsItemSelected(item);
}