Android上的边框颜色按钮 [英] Border color on Android button

查看:126
本文介绍了Android上的边框颜色按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个按钮,并设置了背景颜色和文字颜色,如下所示。我的问题是:如何设置按钮边框颜色?我想将边框颜色设置为白色

I have a button created and have set the background color and text color as can be seen below. My question is: how do I set the buttons border color? I want to set the border color to white

这是我的 res - >中的按钮。布局 - > 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 - >值 - >样式。前2个项目自己工作正常。最后的项目是我尝试将按钮边框更改为白色而没有成功。

And here is its associated style in res -> values -> styles. The first 2 "items" work fine on their own. The final "item" was my attempt at changing button border to white without success.

<!-- 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> ; 元素。将此xml文件作为button_border.xml添加到res / drawable文件夹中:

Use the <stroke> element. Add this xml file in res/drawable folder as 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_boarder"
   android:text="Button" 
/>

'''''''

这篇关于Android上的边框颜色按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆