无法与Android的动作栏下拉导航更改文本颜色 [英] Can't change the text color with Android Action Bar drop-down navigation

查看:168
本文介绍了无法与Android的动作栏下拉导航更改文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下拉导航我的行动吧,用一个黑暗的操作栏时,我不能得到一个合理的颜色相应的文本。操作栏本身就是一个暗灰色,且文本颜色为黑色,所以这是非常难以阅读。

I'm using Drop-down Navigation with my Action bar, and I can't get a sensible color for the corresponding text when using a dark action bar. The action bar itself is a dark grey, and the text color is black, so it's very hard to read.

我也跟着在操作栏开发人员指南基本说明所以我的code是简单

I followed the basic instructions on the Action Bar developer's guide so my code is simply

SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item);
ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {
    @Override
    public boolean onNavigationItemSelected(int itemPosition, long itemId) {
        // TODO
        return false;
    }
};
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);        
actionBar.setListNavigationCallbacks(mSpinnerAdapter, navigationListener);

和我的styles.xml只是

and my styles.xml was simply

<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    </style>
</resources>

我的认为的,应该给我一些明智的,但如下面的图像显示,它出来为黑色文本在暗灰色的背景,因此是没有好。

I think that should have given me something sensible, but as the following image shows, it comes out as black text on a dark grey background so it's no good.

我试着摆弄styles.xml文件,试图解决这个问题。我最好的尝试是以下

I've tried playing around with the styles.xml file to try and solve the problem. My best attempt was the following

<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
        <item name="android:actionDropDownStyle">@style/myActionDropDownStyle</item>
        <item name="android:actionBarStyle">@style/myActionBar</item>
    </style>

    <style name="myActionDropDownStyle" parent="android:style/Widget.Holo.Light.Spinner">
        <item name="android:background">@color/LightCyan</item>
    </style>

    <style name="myActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">    
        <item name="android:titleTextStyle">@style/myActionBar.titleTextStyle</item>
    </style>

    <style name="myActionBar.titleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title.Inverse">
        <item name="android:textColor">@color/Orange</item>
    </style>
</resources>

这是(1)能够改变的应用程序标题橙色文字的颜色,(2)能够改变所选择的导航项目的背景颜色操作栏中浅蓝色,(3)能够改变下拉的背景颜色,使得至少上的黑色文字显示对一个光背景。我做的不过没有改变文字颜色本身,无论是在操作栏中显示所选择的项目,或在下拉列表中显示的项目。我最好的尝试也看起来可怕: - !(

which was (1) able to change the text color of the app title to Orange, (2) able to change the background color of the selected navigation item in the action bar to a light blue, (3) able to change the background color of the dropdown so that at least the black text is shown against a light background. However nothing I do changes the text color itself, either for the selected item shown in the action bar, or for the items shown in the dropdown. My best attempt also looks horrible :-(!

我要的是一个合理的文本颜色操作栏中显示所选择的项目,应该是使用相同的文字颜色,当一个项目被选定一个黑暗的操作栏,并与背景颜色下拉时一个项目被选择为相同的颜色作为操作栏。但是我不知道如何做到这一点,任何人都可以帮忙吗?

All I want is a dark action bar with a sensible text color for the selected item shown in the action bar, which should be the same text color used when an item is being selected, and with the background color for the dropdown when an item is being selected being the same color as the action bar. But I can't work out how to do it, can anyone help?

通知你,我使用Eclipse与ADT-包,我下载了最近(ADT-束的Windows x86_64-20130219)。当我寻找解决办法,我找了很多关于福尔摩斯行动起来吧,不过样式福尔摩斯并没有包括在ADT-包。在任何情况下,可以肯定的是我想应该是可能的,我使用的Holo.Light.DarkActionBar?

FYI, I'm using Eclipse with an adt-bundle that I downloaded very recently (adt-bundle-windows-x86_64-20130219). When I search for solutions, I find a lot about the Sherlock action bar, however the styles for Sherlock weren't included in that adt-bundle. In any case, surely what I want should be possible with the Holo.Light.DarkActionBar that I'm using?

推荐答案

我工作了,我可以改变颜色的下拉导航在code,通过创建自己的ArrayAdapter的子类,如下所示:

I've worked out that I can alter the colors for the drop-down Navigation in code, by creating my own subclass of ArrayAdapter as follows:

public class myArrayAdaptor<T> extends ArrayAdapter<T> {

    public myArrayAdaptor(Context context, int textViewResourceId, T[] objects) {
        super(context, textViewResourceId, objects);
    }

    public static myArrayAdaptor<CharSequence> createFromResource(Context context, int textArrayResId, int textViewResId) {
        CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
        return new myArrayAdaptor<CharSequence>(context, textViewResId, strings);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return SetColourWhite(super.getView(position, convertView, parent));
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return SetColourWhite(super.getView(position, convertView, parent));
    }

    private View SetColourWhite(View v) {
        if (v instanceof TextView) ((TextView)v).setTextColor(Color.rgb(0xff, 0xff, 0xff)); // white
        return v;
    }
}

然后用简单的styles.xml

Then with the simple styles.xml

<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    </style>
</resources>

我可以替代类myArrayAdaptor

I can substitute the class myArrayAdaptor

SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.action_list, android.R.layout.simple_spinner_dropdown_item)

和文字颜色将永远是白色的。但目前还没有这样做,使用设置在styles.xml文件的一个简单的方法?

and the text color will always be white. But isn't there a simpler way of doing this using settings in the styles.xml file?

这篇关于无法与Android的动作栏下拉导航更改文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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