为什么我的可绘制按钮布局没有作为背景应用于按钮?
Why is my drawable button layout not being applied to the button as a background?
我创建了一个 buttonbg.xml 文件来为按钮提供自定义颜色的圆形。
这是 xml 代码的样子,
<stroke
android:color="#69B9F9"
android:width="3dp" />
<corners
android:radius="200dp" />
但是当我将此 xml 用作按钮的背景时,
<Button android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="59dp"
android:layout_marginEnd="61dp"
android:layout_marginBottom="227dp"
android:background="@drawable/button_bg"
android:text="LOGIN"
android:textSize="22sp" />
没有任何反应,
Button Image
请帮帮我!
将此添加到您的按钮
app:backgroundTint="@null"
在你的问题中你也写了
I have created a buttonbg.xml file
并在您的代码中编写了 button_bg.xml。请检查您的代码中是否存在拼写错误或仅存在于问题本身
您可以创建按钮可绘制对象并将该可绘制对象应用于线性布局或任何其他布局。所以基本上创建自定义按钮是实现自定义按钮的非常简单的方法。
如果您不想在每次要为按钮添加背景时都使用 app:backgroundTint="@null
,这里有一个提示。转到您的 themes.xml 文件。在第一个 style 标签中,您会看到
<style name="Theme.[AppName]" parent="Theme.MaterialComponents...."
所以将 parent 更改为 "Theme.AppCompat.Light.DarkActionBar"(如果你不介意操作栏顶部有你的应用程序名称的东西)或 "Theme.AppCompat.Light.NoActionBar"(如果你不想要操作栏。
因此,它的作用是删除默认按钮样式,只为您提供一个普通的灰色按钮,如果您从那里学习,您可能已经在 youtube 上的一些教程中看到过。
我创建了一个 buttonbg.xml 文件来为按钮提供自定义颜色的圆形。 这是 xml 代码的样子,
<stroke
android:color="#69B9F9"
android:width="3dp" />
<corners
android:radius="200dp" />
但是当我将此 xml 用作按钮的背景时,
<Button android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="59dp"
android:layout_marginEnd="61dp"
android:layout_marginBottom="227dp"
android:background="@drawable/button_bg"
android:text="LOGIN"
android:textSize="22sp" />
没有任何反应,
Button Image
请帮帮我!
将此添加到您的按钮
app:backgroundTint="@null"
在你的问题中你也写了
I have created a buttonbg.xml file
并在您的代码中编写了 button_bg.xml。请检查您的代码中是否存在拼写错误或仅存在于问题本身
您可以创建按钮可绘制对象并将该可绘制对象应用于线性布局或任何其他布局。所以基本上创建自定义按钮是实现自定义按钮的非常简单的方法。
如果您不想在每次要为按钮添加背景时都使用 app:backgroundTint="@null
,这里有一个提示。转到您的 themes.xml 文件。在第一个 style 标签中,您会看到
<style name="Theme.[AppName]" parent="Theme.MaterialComponents...."
所以将 parent 更改为 "Theme.AppCompat.Light.DarkActionBar"(如果你不介意操作栏顶部有你的应用程序名称的东西)或 "Theme.AppCompat.Light.NoActionBar"(如果你不想要操作栏。
因此,它的作用是删除默认按钮样式,只为您提供一个普通的灰色按钮,如果您从那里学习,您可能已经在 youtube 上的一些教程中看到过。