如何在 Android Studio 中更改 textView 形状和颜色
我到处寻找改变 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论