Kotlin不应用样式

发布于 2025-01-18 09:05:08 字数 1184 浏览 0 评论 0原文

我在 themes.xml 中创建了一个按钮样式定义,如下所示:

    <style name="MyAppTheme.Button" parent="Widget.AppCompat.Button.Colored">
        <item name="android:textSize">16sp</item>
        <item name="android:letterSpacing">0.06</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:background">@color/brand04</item>
    </style>

我按如下方式应用它:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <variable name="text"  type="String"/>
    </data>

    <Button
        android:theme="@style/MyAppTheme.Button"
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true"
        android:enabled="true"
        android:letterSpacing="0.5"
        android:paddingTop="25dp"
        android:paddingBottom="25dp"
        android:text="@{text}"/>
</layout>

我使用 include 将按钮包含到不同的布局中。

这种风格从未被应用过,

知道为什么吗?

I have created a button style defines in the themes.xml as below:

    <style name="MyAppTheme.Button" parent="Widget.AppCompat.Button.Colored">
        <item name="android:textSize">16sp</item>
        <item name="android:letterSpacing">0.06</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:background">@color/brand04</item>
    </style>

I apply it as followed:

<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <variable name="text"  type="String"/>
    </data>

    <Button
        android:theme="@style/MyAppTheme.Button"
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:focusable="true"
        android:enabled="true"
        android:letterSpacing="0.5"
        android:paddingTop="25dp"
        android:paddingBottom="25dp"
        android:text="@{text}"/>
</layout>

I am using include to include the button into different layout.

The style is never applied

any idea why ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤千羽 2025-01-25 09:05:08

您必须更新词根主题父,而不是按钮 parent

<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar.Bridge">
</?

https://i.sstatic.net/sv0y2.png“ alt =” them.xml“>

”

You have to update your root theme parent not the Button parent

<style name="AppTheme" parent="Theme.MaterialComponents.NoActionBar.Bridge">
</?

Theme.xml

include_button_xml

长安忆 2025-01-25 09:05:08

您需要使用AppCompatbutton。
然后,您可以应用样式。

you need to use AppCompatbutton.
You can then apply style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文