我已经创建了一个按钮,并设置了背景颜色和文本颜色,如下所示。我的问题是:如何设置按钮的边框颜色?我想将边框颜色设置为白色
这是我的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
中的相关样式。前两个“项目”本身就工作得很好。最后一个“项目”是我尝试将按钮边框改为白色,但没有成功。
<!-- 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>
发布于 2013-09-26 00:44:27
使用<stroke>
元素。将此xml文件添加到res/drawable文件夹中,作为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"
/>
发布于 2015-03-16 15:10:51
尝尝这个
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="1dp" />
<stroke
android:width="2px"
android:color="#ffffff" />
</shape>
发布于 2014-05-11 19:15:54
您可以使用此联机按钮生成器来自定义按钮http://angrytools.com/android/button/
https://stackoverflow.com/questions/19010573
复制相似问题