简体   繁体   English

将按钮半径设置为主题

[英]Set button radius as a theme

<Button android:id="@+id/gp_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="32dp"
    android:onClick="gp"
    android:text="@string/go_gplay"
    android:textAllCaps="false"
    android:theme="@style/ButonTheme"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.502"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />    

<style name="ButonTheme" parent="ButonTheme">
    <item name="android:backgroundTint">#ffffff</item>
    <item name="android:textColor">#121212</item>
    <item name="android:topLeftRadius">20dp</item>
    <item name="android:bottomLeftRadius">20dp</item>
    <item name="android:topRightRadius">20dp</item>
    <item name="android:bottomRightRadius">20dp</item>
</style>

How can I edit button border radius as a theme, as you see i set the radius to 20dp and in preview it shows ok, but when compile and run it in phone it shows the radius by default.(i know the other "trick" to make a shape and then set it as button background, but in this way i will loose the "material" default animation) 如何将按钮边框半径作为主题进行编辑,如您所见,我将半径设置为20dp并在预览中显示为确定,但是在编译并在手机中运行时,默认情况下显示为半径。(我知道另一个“技巧”来制作形状,然后将其设置为按钮背景,但是这样,我将松开“材质”默认动画)

Make a drawable.. and then apply the drawables filename as a background to the <Button> within your layout. 制作一个drawable ..,然后将drawables文件名作为背景应用于布局中的<Button>

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#ffffffff"/>    

    <stroke android:width="3dp"
            android:color="#ff000000" />

    <padding android:left="1dp"
             android:top="1dp"
             android:right="1dp"
             android:bottom="1dp" /> 

    <corners android:bottomRightRadius="7dp"
             android:bottomLeftRadius="7dp"
             android:topLeftRadius="7dp"
             android:topRightRadius="7dp" /> 
</shape>

try setting radius for whole corners , <item name android:radius="20dp"/> or you maybe can put your button in a card view and curve it's corners. 尝试设置整个角的半径, <item name android:radius="20dp"/>或者您也可以将按钮放在卡片视图中并弯曲它的角。 but the typical way is using shape. 但典型的方法是使用形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM