我创建了一个按钮并设置了背景颜色和文本颜色,如下所示。我的问题是:如何设置按钮边框颜色?我想将边框颜色设置为白色
这是我的 res -> layout -> main_nav.xml
<Button
android:id="@+id/btn_emergency"
style="@style/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Contact and Emergency"
android:onClick="onClickHandleStates" />
这是它在 res -> values -> styles
中的关联样式。前 2 个“项目”可以自行正常工作。最后一个“项目”是我尝试将按钮边框更改为白色但没有成功。
<!-- The button styles -->
<style name="buttonStyle">
<item name="android:textColor">#ffffff</item>
<item name="android:background">#80000000</item>
<item name="android:button">
<shape
android:shape="rectangle" >
<stroke
android:width="0.5dp"
android:color="#ffffff" />
</shape>
</item>
</style>
最佳答案
使用 <stroke>
元素。在 res/drawable 文件夹中添加这个 xml 文件作为 button_border.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF"
android:endColor="#00FF00"
android:angle="270" />
<corners android:radius="3dp" />
<stroke android:width="5px" android:color="#ffffff" />
</shape>
然后调用它
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="@drawable/button_border"
android:text="Button"
/>
关于android - Android 按钮上的边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19010573/