Android 为什么将AppTheme应用于自定义ActionBar工具栏?
我正在使用自定义Android 为什么将AppTheme应用于自定义ActionBar工具栏?,android,android-actionbar,themes,toolbar,Android,Android Actionbar,Themes,Toolbar,我正在使用自定义工具栏。因此,我将AppTheme(BaseTheme)设置为NoActionBar 我运行了应用程序,但是自定义的工具栏仍然有应用主题的颜色 在此状态下,我还更改了AppTheme的颜色。顺便说一下,工具栏的颜色已经改变了 我不知道为什么会这样 AppThemesetNoActionbar,我曾使用自定义工具栏,但没有在自定义工具栏上设置任何主题 但是为什么自定义工具栏会受到基本主题的影响呢 这是代码 Manifest.xml <manifest xmlns:androi
工具栏
。因此,我将AppTheme
(BaseTheme)设置为NoActionBar
我运行了应用程序,但是自定义的工具栏
仍然有应用主题
的颜色
在此状态下,我还更改了AppTheme的颜色。顺便说一下,工具栏的颜色已经改变了
我不知道为什么会这样
AppTheme
setNoActionbar
,我曾使用自定义工具栏,但没有在自定义工具栏上设置任何主题
但是为什么自定义工具栏会受到基本主题的影响呢
这是代码
Manifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.writeweight">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.WriteWeight">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="ㅅㅅㅅ"/>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
values.themes.xml
<style name="Theme.WriteWeight" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
@颜色/紫色500
@颜色/紫色\u 700
@颜色/白色
@颜色/青色200
@颜色/青绿色700
@颜色/黑色
?attr/colorPrimaryVariant
谢谢。使用它
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
它将采用原色
自定义样式
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
style="@style/Widget.MaterialComponents.Toolbar.Primary"
/>
因此,如果我更改Theme.WriteView的colorPrimary,无论我设置了什么,工具栏的颜色都会改变吗?这里我们将相应的颜色作为属性。Source colors.xml。你想问什么还不清楚。虽然我理解它是NoActionBar,但颜色值不会改变。也许它会有帮助?属性/对属性的引用。属性是应用程序主题中指定的值。示例中的属性都是在支持库提供的主题中指定的值。Android也有自己的属性,可以与?Android:attr/.attr一起使用。Source colors.xml?但当我在values.themes.xml中更改primaryColor时,工具栏的颜色发生了变化。。primaryColor存在于values.themes.xml.及其主题集NoActionBar中。但是,我在values.themes.xml中更改了primaryColor,自定义工具栏的颜色也更改了。但自定义工具栏不设置主题。为什么primaryColor应用于自定义工具栏?工具栏未设置主题,工具栏与主题中的primaryColor无关。WriteView?