hey*_*red 23 xml eclipse android border button
我创建了一个按钮,并设置了背景颜色和文本颜色,如下所示.我的问题是:如何设置按钮边框颜色?我想将边框颜色设置为白色
这是我的按钮 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" />
Run Code Online (Sandbox Code Playgroud)
这是它的相关风格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>
Run Code Online (Sandbox Code Playgroud)
shi*_*edi 34
使用<stroke>元素.将此xml文件作为button_border.xml添加到res/drawable文件夹中:
<?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>
Run Code Online (Sandbox Code Playgroud)
然后打电话给
<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"
/>
Run Code Online (Sandbox Code Playgroud)
试试这个
<?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>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="270"
android:endColor="#E8f2fe"
android:startColor="#E8f2fe" />
<corners android:radius="3dp" />
<stroke
android:width="2px"
android:color="#486e9d" />
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请访问http://androiddhina.blogspot.in/2015/09/border-color-on-android-button.html
尝试材质按钮
根据您的需要设置应用程序:描边宽度,应用程序:描边颜色
<com.google.android.material.button.MaterialButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:strokeWidth="0.6dp"
app:cornerRadius="2dp"
android:text="Reassign"
android:textColor="@color/colorAccent"
app:strokeColor="@color/colorAccent"
/>
Run Code Online (Sandbox Code Playgroud)
注意:您需要添加材质小部件的依赖项
//Material Components for Android
implementation 'com.google.android.material:material:1.0.0'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69146 次 |
| 最近记录: |