java - 当我声明为浅色主题时,为什么我会得到深色主题?

标签 java android xml android-theme

我正在开发一个采用 Material 设计的应用程序。

我已向 Activity 添加了一个工具栏,并且已将其主题设置为浅色:app:popupTheme="@style/ThemeOverlay.AppCompat.Light",但运行后我仍然得到一个深色主题。

这是我的 Activity_about.xml 文件的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context="com.abc.xyz.AboutActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

</RelativeLayout>

这是 AboutActivity.java 文件的代码:

public class AboutActivity extends AppCompatActivity {

    Toolbar toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_about);

        SpannableString s = new SpannableString("About");
        s.setSpan(new TypefaceSpan(this, "Pacifico.ttf"), 0, s.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle(s);

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_about, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

这是 styles.xml 文件的代码:

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

    <style name="MyMaterialTheme" parent="MyMaterialTheme.Base">

    </style>

    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <item name="windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

我是 Material 设计新手,因此不知道该怎么做。

请告诉我。

我是 StackOverflow 的新手,所以请配合。

提前致谢。

最佳答案

您必须更改 xml AppTheme

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:theme="@style/ThemeOverlay.Material.Light.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

关于java - 当我声明为浅色主题时,为什么我会得到深色主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32918391/

相关文章:

java - 单击 3 次后删除 ListView 项目

Android OpenCV : how to properly call Looper. 准备()

android - 我的 "Android"首选项中缺少 "Eclipse Juno 4.1"

xml - 如何生成没有尾部 "/"的XML标签?

xml - 创建自定义 XML 映射

java - 一个应用程序中的服务器和 ServerSocket : not working

java - fragment 不可滚动

java - 在 Java 中比较字符串

android - 从 Android 中的前置摄像头拍摄的镜像翻转视频

xml - 在 Inno Setup 中运行 schtask.exe 之前创建带有安装路径的 XML 任务文件