操作栏下拉菜单中开启和关闭的项目风格 [英] Action Bar dropdown open and closed item styles

查看:142
本文介绍了操作栏下拉菜单中开启和关闭的项目风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想风格的动作栏列表导航,使得它在关闭状态白色文本。当我这样做,但是,它已经变成所有文白,不与白色的下拉工作。

I'm trying to style the action bar list navigation such that it has white text in the closed state. When I've done that, though, it has turned all the text white, which doesn't work with the white dropdown.

有没有办法单独样式每个?该文档是不存在的:(

Is there a way to style each individually? The docs are non-existant :(

推荐答案

添加自定义布局的适配器。在这方面,我已创建了一个布局中,我必须添加一个的TextView 。与文本颜色背景颜色

Add Custom Layout for your Adapter. in this i have created one layout inside that i have add one TextView. with text color and background color.

和设置atapter这样的:

and set atapter like:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getBaseContext(), R.layout.my_spinner_style, R.id.textView1,
                COUNTRIES);

下面

R.layout.my_spinner_style 是我的自定义布局。

R.id.textView1 是TextView的ID从 my_spinner_style.xml

R.id.textView1 is textview id from my_spinner_style.xml.

你也可以applay内部的TextView您芒风格。检查的这个的aretical。

you can also applay your awn style inside TextView. check this and this aretical.

检查该code:

的onCreate

/** Create an array adapter to populate dropdownlist */
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                getBaseContext(), R.layout.my_spinner_style, R.id.textView1,
                COUNTRIES);

        /** Enabling dropdown list navigation for the action bar */
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);

        /** Defining Navigation listener */
        ActionBar.OnNavigationListener navigationListener = new OnNavigationListener() {

            @Override
            public boolean onNavigationItemSelected(int itemPosition,
                    long itemId) {
                Toast.makeText(getBaseContext(),
                        "You selected : " + COUNTRIES[itemPosition],
                        Toast.LENGTH_SHORT).show();
                return false;
            }
        };

        /**
         * Setting dropdown items and item navigation listener for the actionbar
         */
        getActionBar().setListNavigationCallbacks(adapter, navigationListener);

my_spinner_style.xml

my_spinner_style.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FFFF00" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Large Text"
        android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

这篇关于操作栏下拉菜单中开启和关闭的项目风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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