[英]How do I change my Buttons color, using android:background gives it white borders?
As you probably already guessed I am quite new to coding.正如您可能已经猜到的那样,我对编码很陌生。 As my First Project i want to code TicTacToe.
作为我的第一个项目,我想编写井字游戏。 It seems like the default color of my Buttons is set to purple and i would like to change that.
我的按钮的默认颜色似乎设置为紫色,我想更改它。 The problem is using "android:background" does nothing.
问题是使用“android:background”什么都不做。 If I use "android:backgroundTint" it changes the color as i want it to but i doesn´t fill the space.
如果我使用“android:backgroundTint”它会改变我想要的颜色,但我不会填充空间。 I appreciate every help, thanks!
我感谢每一个帮助,谢谢!
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.825"
android:id="@+id/table">
<TableRow>
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:backgroundTint="@color/black"
android:text="X"
android:textSize="100dp" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="X"
android:background="@color/white"
android:textSize="100dp" />
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="X"
android:background="@color/white"
android:textSize="100dp" />
The others rows are the same其他行相同
The button by default is a MaterialButton component so to change the background colour you can use the attribute: android:backgroundTint and to fill the space you can use the attributes: android:insetLeft , android:insetTop , android:insetRight and android:insetBottom all to 0dp value. The button by default is a MaterialButton component so to change the background colour you can use the attribute: android:backgroundTint and to fill the space you can use the attributes: android:insetLeft , android:insetTop , android:insetRight and android:insetBottom all为 0dp 值。 Also to remove the default corner radius you have to use the attribute app:cornerRadius to 0dp.
此外,要删除默认角半径,您必须使用属性app:cornerRadius为 0dp。
Below is an example Button which has the above attributes:下面是一个具有上述属性的示例按钮:
<Button
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="X"
android:textSize="100sp"
android:backgroundTint="@color/black"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
app:cornerRadius="0dp" />
And the Result after applying three of them horizontally with different colours and equal space will be like below:将其中三个以不同的颜色和相等的空间水平应用后的结果将如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.