Can';不要为使用主题的按钮更改'android:textColor'
你好,我有一个简单的android应用程序,其中有一个按钮。这是我的应用程序的默认主题:Can';不要为使用主题的按钮更改'android:textColor',android,kotlin,android-button,android-styles,Android,Kotlin,Android Button,Android Styles,你好,我有一个简单的android应用程序,其中有一个按钮。这是我的应用程序的默认主题:themes.xml <resources xmlns:tools="http://schemas.android.com/tools"> <!-- Base application theme. --> <style name="Theme.BaseAppTheme" parent="Theme.Material
themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.BaseAppTheme" 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>
<style name="Theme.WalkTest" parent="Theme.BaseAppTheme">
<item name="android:textColor">@android:color/black</item>
</style>
</resources>
这是我片段中的按钮:fragment\u buildings.xml
(我使用的是导航)
使用
而不是
android:theme="@style/Theme.WalkTest.ButtonSecondary"
使用
而不是
android:theme="@style/Theme.WalkTest.ButtonSecondary"
首先,在values/styles.xml中定义样式 示例:
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="text_h3">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:fontFamily">@font/font_medium</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
</style>
</resource>
<TextView
android:id="@+id/tv_name_label"
style="@style/text_h3"
...
</TextView>
14便士
@颜色/原色
@字体/字体中
真的
真的
?android:attr/selectableItemBackground
第二,使用所需视图的已定义样式
示例:
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="text_h3">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:fontFamily">@font/font_medium</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
</style>
</resource>
<TextView
android:id="@+id/tv_name_label"
style="@style/text_h3"
...
</TextView>
首先,在values/styles.xml中定义样式
示例:
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="text_h3">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:fontFamily">@font/font_medium</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
</style>
</resource>
<TextView
android:id="@+id/tv_name_label"
style="@style/text_h3"
...
</TextView>
14便士
@颜色/原色
@字体/字体中
真的
真的
?android:attr/selectableItemBackground
第二,使用所需视图的已定义样式
示例:
<resources xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
<style name="text_h3">
<item name="android:textSize">14sp</item>
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:fontFamily">@font/font_medium</item>
<item name="android:clickable">true</item>
<item name="android:focusable">true</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
</style>
</resource>
<TextView
android:id="@+id/tv_name_label"
style="@style/text_h3"
...
</TextView>
这是一个将样式直接应用于视图的示例。然而,问题是关于通过主题应用样式。@homerman不,实际上没问题。我只是想找到一种定义样式并应用它们的方法,哈哈。这是一个将样式直接应用于视图的示例。然而,问题是关于通过主题应用样式。@homerman不,实际上没问题。我只是想找到一种定义样式并应用它们的方法。