更改动作条homeAsUpIndicator Programamtically [英] Change the actionbar homeAsUpIndicator Programamtically

查看:186
本文介绍了更改动作条homeAsUpIndicator Programamtically的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的技巧以编程方式更改homeAsupIndicator。

I used the following hack to change the homeAsupIndicator programmatically.

int upId = Resources.getSystem().getIdentifier("up", "id", "android");
if (upId > 0) {
    ImageView up = (ImageView) findViewById(upId);
up.setImageResource(R.drawable.ic_action_bar_menu);
up.setPadding(0, 0, 20, 0);
}

不过,这是行不通的大多数新款手机(HTC一,银河S3等)。有,可均匀地改变跨设备的方法。我需要它只能在主屏幕改变。其他屏幕将有默认的。所以不能使用styles.xml

But this is not working on most new phones (HTC One, Galaxy S3, etc). Is there a way that can be changed uniformly across devices. I need it to be changed only on home screen. Other screens would have the default one. So cannot use the styles.xml

推荐答案

这是我做过什么获得了这幅行为。我继承了基本主题,并创建了一个新的主题,用它作为主题,为特定的活动。

This is what i did to acheive the behavior. I inherited the base theme and created a new theme to use it as a theme for the specific activity.

<style name="CustomActivityTheme" parent="AppTheme">
    <item name="android:homeAsUpIndicator">@drawable/custom_home_as_up_icon</item>
</style>

而在Android清单我所做的活动主题,上面。

and in the android manifest i made the activity theme as the above.

<activity
        android:name="com.example.CustomActivity"
        android:theme="@style/CustomActivityTheme" >
</activity>

的伟大工程。将再次更新,当我检查我的所有设备。感谢@faylon您指出了正确的方向。

works great. Will update again when i check on all devices I have. Thanks @faylon for pointing in the right direction

这篇关于更改动作条homeAsUpIndicator Programamtically的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆