Java 当我宣布它是光明的时候,为什么我会变得黑暗?

Java 当我宣布它是光明的时候,为什么我会变得黑暗?,java,android,xml,android-theme,Java,Android,Xml,Android Theme,我正在开发一个材料设计的应用程序 我已经在活动中添加了一个工具栏&我已经在这里将其主题设置为浅:app:popupTheme=“@style/ThemeOverlay.AppCompat.light”,但运行后我仍然得到了一个暗主题 下面是我关于.xml文件代码的活动: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://

我正在开发一个材料设计的应用程序

我已经在活动中添加了一个工具栏&我已经在这里将其主题设置为浅:
app:popupTheme=“@style/ThemeOverlay.AppCompat.light”
,但运行后我仍然得到了一个暗主题

下面是我关于.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>
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);
    }
}
<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>
下面是styles.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>
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);
    }
}
<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>

真的
假的
@颜色/原色
@颜色/原色暗
@颜色/颜色重音
我不熟悉材料设计,因此不知道该怎么做

请让我知道

我是StackOverflow的新手,请配合


提前感谢。

您必须更改xmlAppTheme

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

您必须更改xmlAppTheme

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

您必须在xml文件中创建工具栏主题

在styles.xml中

 <style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">

    <item name="colorPrimary">@color/seccolor</item>
    <item name="colorControlHighlight">@color/md_white_1000</item>
</style>

@颜色/秒颜色
@颜色/md_白色_1000
现在在主xml文件中使用它

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?attr/colorPrimaryDark"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Light"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_gravity="center_horizontal|top" />


它应该会起作用

您必须在xml文件中创建工具栏主题

在styles.xml中

 <style name="ToolbarTheme" parent="ThemeOverlay.AppCompat.Light">

    <item name="colorPrimary">@color/seccolor</item>
    <item name="colorControlHighlight">@color/md_white_1000</item>
</style>

@颜色/秒颜色
@颜色/md_白色_1000
现在在主xml文件中使用它

<android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?attr/colorPrimaryDark"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Light"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:layout_gravity="center_horizontal|top" />


它应该会起作用

app:popupTheme属性用于菜单弹出窗口以及覆盖工具栏的所有其他弹出窗口

可能是您的工具栏没有设置主题,因为您没有在
AndroidManifest.xml
中引用正确的主题

确保是这样的:

<manifest>
    <application
        ...
        android:theme="@style/MyMaterialTheme.Base">

        <activity/>
        ...

    </application>
</manifest>

...

这将为应用程序中的所有活动设置主题。您甚至可以将其应用于单个活动。

app:popupTheme属性用于菜单弹出窗口以及覆盖工具栏的所有其他弹出窗口

可能是您的工具栏没有设置主题,因为您没有在
AndroidManifest.xml
中引用正确的主题

确保是这样的:

<manifest>
    <application
        ...
        android:theme="@style/MyMaterialTheme.Base">

        <activity/>
        ...

    </application>
</manifest>

...

这将为应用程序中的所有活动设置主题。您甚至可以将其应用于个人活动。

style.xml中

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


真的
假的
@颜色/原色
@颜色/原色暗
@颜色/颜色重音

主主题的父级是

在你的
MyMaterialTheme.Base中也有父项作为

.darkaActionBar
从这两者中删除将有所帮助。然后,您可以像上面的答案中提到的那样为工具栏添加样式


希望有帮助。

在您的
style.xml中

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


真的
假的
@颜色/原色
@颜色/原色暗
@颜色/颜色重音

主主题的父级是

在你的
MyMaterialTheme.Base中也有父项作为

.darkaActionBar
从这两者中删除将有所帮助。然后,您可以像上面的答案中提到的那样为工具栏添加样式


希望有帮助。

这里的问题是我没有为工具栏应用主题

我修复了这个问题,只添加了这一行:
android:theme=“@style/ThemeOverlay.AppCompat.Dark.ActionBar”
到xml文件中的我的工具栏小部件


谢谢大家的努力

这里的问题是我没有为工具栏应用主题

我修复了这个问题,只添加了这一行:
android:theme=“@style/ThemeOverlay.AppCompat.Dark.ActionBar”
到xml文件中的我的工具栏小部件


谢谢大家的努力

请检查style.xml以了解应用程序主题!请检查style.xml以了解应用程序主题!将父主题从
parent=“theme.AppCompat.Light.DarkActionBar”
更改为
parent=“theme.AppCompat.Light.ActionBar”
后。它的内容是:
“无法解析symbol:parent=“Theme.AppCompat.Light.ActionBar”“
”。现在要做什么?检查编辑以了解更多信息,并在将父主题从
parent=“theme.AppCompat.Light.darkaActionBar”更改为
parent=“theme.AppCompat.Light.ActionBar”后检查此操作。它的内容是:
“无法解析symbol:parent=“Theme.AppCompat.Light.ActionBar”“
”。现在要做什么?检查编辑以了解更多信息,并检查此项