【问题标题】:Up Button Customization in Action Bar操作栏中的向上按钮自定义
【发布时间】:2013-08-21 08:30:17
【问题描述】:

我想在操作栏中添加一个标准的向上按钮图标(

我在样式中添加了这个:

<style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:homeAsUpIndicator">@drawable/navigation_previous_item</item>
</style>

我在onCreate 中启用了主页按钮:

getActionBar().setHomeButtonEnabled(true);

并添加动作事件:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()){
            case android.R.id.home:
                onBackPressed();
                break;
            default:
                return super.onOptionsItemSelected(item);
        }
       return true;
    }

问题是我看不到 (

【问题讨论】:

  • 您还需要拨打:getActionBar().setDisplayHomeAsUpEnabled(true)。查看启用选项后使用getActionBar().setHomeAsUpIndicator(getResources().getDrawable(R.drawable.navigation_previous_item)) 是否有帮助。
  • 非常感谢,我认为我正在调用该方法:D
  • 不客气。您可以接受 @andreich 的回答,因为它提出了相同的方法。
  • setHomeAsUpIndicator 仅在 api 18 中添加,除非您使用支持库 appcompat 操作栏...

标签: android navigation styles android-actionbar


【解决方案1】:

试试getActionBar().setDisplayHomeAsUpEnabled(true);,它应该可以工作

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-07
    • 1970-01-01
    相关资源
    最近更新 更多