更改homeAsUpIndicator动态 [英] Change homeAsUpIndicator dynamically

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

问题描述

我建有四个选项卡的应用程序,并作为结果,4个片段。在第一个片段,我有一个滑动菜单和我扔在了动作条自定义图标。现在的问题是,在别人的片段,我想stablish其他自定义图标返回到第一个片段,但我不知道该怎么办......

I build an app with four tabs and, as a consequence, four fragments. In the first fragment, I have a sliding menu and I throw with a custom icon in the actionbar. The problem is that in the others fragments, I want to stablish other custom icon to return to the first fragment but I don't know what to do...

这是我的styles.xml与滑动菜单我的自定义图标:

This is my styles.xml with my custom icon for the sliding menu:

<!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:homeAsUpIndicator">@drawable/menu32</item>
    </style>

在Java code效果很好,但我不知道如何动态地更改图标。

The java code works well but I don't know how to change the icon dynamically.

这是我有:

推荐答案

您可以使用下面的在你的片段:

You can use the following in your fragments:

Actionbar ab = getActivity().getActionBar();
ab.setIcon(icon);

其中,图标是一个可绘制或资源ID,当向上的指标是你的图标的一部分。
您也可以使用<一个href="http://developer.android.com/reference/android/app/ActionBar.html#setHomeAsUpIndicator%28int%29"相对=nofollow> setHomeAsUpIndicator ,如果​​你使用的API级> 11

Where icon is a Drawable or a resource id, when the up indicator is a part of your icon.
You can also use setHomeAsUpIndicator if you use API level > 11:

getActivity().getActionBar().setHomeAsUpIndicator(resId);

如果你的API水平较低,那么我建议你使用ActionbarSherlock的。

If your API level is lower, then I suggest you make use of ActionbarSherlock.

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

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