操作栏下拉菜单中开启和关闭的项目风格风格、操作、项目、菜单中

2023-09-12 03:20:57 作者:_纯白、紫色

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

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>