简体   繁体   English

如何更改我的按钮颜色,使用 android:background 给它白色边框?

[英]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.

相关问题 如何更改我的 Android 应用程序列的背景颜色 - How do I change the background color for a column of my Android app 如何使用彩色按钮作为用户选择从第二个活动更改我的 MainActivity 的背景颜色? - How can I change the background color of my MainActivity from a second activity using colored buttons as user choices? 如何根据用户输入更改android应用的背景颜色? - How do I change the background color of my android app based on user input? 如何使用 JRadioButton 更改 JPanel 的背景颜色 - How do I change the background color of a JPanel using JRadioButton 如何使用复选框更改java中的背景颜色? - How do I change the background color in java using a checkbox? 如何更改所有按钮的背景色? - How Do You Change The Background Color of All Buttons? (Java) 我的所有按钮周围都有白色边框 - (Java) There are white borders around all my buttons 如何将JTable背景色默认为白色? - how to change JTable Background Color default to white? 如何在 Android 中更改 canvas 上的油漆颜色/厚度? - How do I change the color/thickness of my paint on a canvas in Android? 如何更改 Android 应用程序中时间选择器的颜色? - How do I change the color of the timepicker in my Android app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM