如何在 Android Studio 中更改 textView 形状和颜色

发布于 2025-01-16 09:16:30 字数 1379 浏览 3 评论 0原文

我到处寻找改变 textView 形状和颜色的方法,我能找到的唯一解决方案是制作一个可绘制的资源文件。我做了什么: rounded_blue.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00BCD4" />
    <stroke
        android:width="3dp"
        android:color="#ffffff" />
    <corners android:radius="30dp" />
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
</shape>

但是当我将它应用到我的 textView 时,我得到了形状,但没有得到颜色。颜色变为默认颜色。

<Button
        android:id="@+id/loginButton"
        android:layout_width="249dp"
        android:layout_height="45dp"
        android:text="Login"
        android:background="@drawable/rounded_blue"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/button_standard"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/button_standard"
        app:layout_constraintTop_toBottomOf="@+id/edittext_password"
        app:layout_constraintVertical_bias="0.086" />```

[This is what I get ][1]


  [1]: https://i.sstatic.net/f5P8Y.png

The edges are rounded as I wanted, but I want to change the button color. Why won't the color translate over as well?T

I have looked everywhere to change the textView shape AND color and the only solution I can find is to make a drawable resource file. Which I did:
rounded_blue.xml

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#00BCD4" />
    <stroke
        android:width="3dp"
        android:color="#ffffff" />
    <corners android:radius="30dp" />
    <padding
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp" />
</shape>

But when I apply it to my textView I get the shape but not the color. The color goes to default.

<Button
        android:id="@+id/loginButton"
        android:layout_width="249dp"
        android:layout_height="45dp"
        android:text="Login"
        android:background="@drawable/rounded_blue"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="@+id/button_standard"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/button_standard"
        app:layout_constraintTop_toBottomOf="@+id/edittext_password"
        app:layout_constraintVertical_bias="0.086" />```

[This is what I get ][1]


  [1]: https://i.sstatic.net/f5P8Y.png

The edges are rounded as I wanted, but I want to change the button color. Why won't the color translate over as well?T

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文