android - 操作栏下拉打开和关闭项目样式

标签 android android-actionbar

我正在尝试设置操作栏列表导航的样式,使其在关闭状态下具有白色文本。但是,当我这样做时,它已将所有 文本变成白色,这不适用于白色下拉菜单。

有没有办法分别设置每个样式?文档不存在 :(

screenshot

最佳答案

为您的适配器添加自定义布局。在此我创建了一个布局,其中添加了一个 TextView。使用 text colorbackground color

并像这样设置一个适配器:

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

这里

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

R.id.textView1 是来自 my_spinner_style.xml 的 TextView ID。

您还可以在 TextView 中应用您的 awn 样式。检查 thisthis文章。

检查这段代码:

enter image description here

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

<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>

关于android - 操作栏下拉打开和关闭项目样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15824793/

相关文章:

android - ShareActionProvider 在 android 中没有任何操作栏

android - OpenGL Android 应用程序适用于大多数手机,但纹理在 Xoom 上显示为白色

android - relativelayout 中的第一个 View 展开以填充剩余空间

android - 如何从 Android Espresso 测试的 google Firebase 获取代码覆盖率报告

android - Sherlock ActionBar 溢出菜单 TextColor

Android ActionBar 菜单项可滚动

android - 如何将 editText 值传递给 viewModel 和 Livedata (Kotlin)

android - android MediaPlayer res原始文件夹getContentUri

android - 抽屉导航覆盖 Actionbar

android - 应在哪个 UI 组件中使用过滤器和/或排序?