【发布时间】:2021-05-23 22:12:32
【问题描述】:
我正在尝试自定义我的 Android 主题,但似乎没有任何效果。
活动:
public class MainActivity extends AppCompatActivity {
...
}
主题.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Delete" parent="Theme.MaterialComponents.Light">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryVariant">@color/primary</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/primary</item>
<item name="colorSecondaryVariant">@color/primary</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
<item name="materialButtonStyle">@style/Widget.App.Button</item>
</style>
<style name="Widget.App.Button" parent="Widget.MaterialComponents.Button">
<item name="materialThemeOverlay">@style/ThemeOverlay.Button</item>
<item name="colorPrimary">@color/primary</item>
</style>
<style name="ThemeOverlay.Button" parent="" >
<!-- For filled buttons, your theme's colorPrimary provides the default background color of the component-->
<item name="colorPrimary">@color/primary</item>
</style>
</resources>
在布局中我使用 Material Design Components 为例
<com.google.android.material.button.MaterialButton
android:id="@+id/button_home_all"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/home_all"
app:layout_constraintStart_toStartOf="parent"/>
但默认的purple_200 背景颜色应用于按钮。你能帮帮我吗?我读到我应该使用Activity 而不是AppCompatActivity 但我无法更改它,因为我的活动是底部导航活动我找不到对onSupportNavigateUp 或其他相关内容的支持
编辑
AndroidManifest.xml<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="licenta.allbank">
<application
android:requestLegacyExternalStorage="true"
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.AllBank"
android:usesCleartextTraffic="true">
<activity
android:name=".activity.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="@string/app_name"
android:launchMode="singleInstance"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="callback"
android:scheme="https" />
</intent-filter>
</activity>
</application>
</manifest>
【问题讨论】:
-
您可以在设置主题的地方包含清单吗?
-
@HenryTwist 完成
标签: android material-design android-button android-theme material-components-android