4.2.2之前只有logo可以点击。
从 4.2.2 开始,操作栏的标题可以与 Logo 一起单击 - 两者就像是同一个按钮的一部分。
您可以在 Google 阅读器应用程序中看到此行为的示例 - 如果您有 4.2.2 设备(请参阅随附的屏幕截图)。
如何禁用此行为并启用仅单击图标?也许这是一个错误?
查看示例代码 fragment :
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
return true;
}
return false;
}
}
最佳答案
这个答案似乎相关:https://stackoverflow.com/a/16216966/596531
我自己还没有尝试过,因为它充其量只是一种变通方法并且使我的代码复杂化,但是通过隐藏真实标题它应该可以解决问题。
关于Android 4.2.2 使操作栏图标和标题可点击,就好像是同一个按钮的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15072016/