【发布时间】:2021-06-06 10:40:32
【问题描述】:
我有一个 XML 文件,它用颜色和可绘制对象定义了应用程序 UI,但它们似乎都被来自themes.xml 的主题所覆盖。如何禁用此功能?
例子:
这个按钮:
<Button
android:id="@+id/capture_button"
android:layout_width="match_parent"
android:background="@drawable/round_button"
android:layout_height="0dp"
android:text="@string/capture_button_text_en"
android:textColor="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/camera_activity_frameLayout">
</Button>
应该有一个黑色背景,因为它在 round_button.xml 中定义:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/black"/>
<corners android:radius="7dp"/>
<stroke android:width="1dp" android:color="@color/white"/>
</shape>
不过是紫色,来自主题的颜色:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.myproject" 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>
</resources>
如何覆盖这个主题?
【问题讨论】:
标签: android android-studio android-layout android-view android-theme