Android 自定义Button样式后变扁
阿神
阿神 2017-04-17 11:58:12
0
3
384

效果如下 (第二个按钮)


所有的按钮均在一个带有android:stretchColumns="*"TableLayout的多个TableRow下。下帖代码。


main.xml

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/gray_bg"
    android:text="@string/calculator_multiply"
/>

gray_bg.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="5dp"/>
    <item android:drawable="@drawable/gray_default" android:state_pressed="false"></item>
    <item android:drawable="@drawable/gray_active" android:state_pressed="true"></item>
</selector>

gray_default.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="5dp"/>
    <solid android:color="@color/gray_default"/>
</shape>

gray_active.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <corners android:radius="5dp"/>
    <solid android:color="@color/gray_active"/>
</shape>
阿神
阿神

闭关修行中......

reply all(3)
左手右手慢动作

This is related to the Theme set by your application. This will happen if it is android:Theme or android:Theme.Black

Solution 1: Change Theme to android:Theme.Holo or android:Theme.Holo.Light

Solution 2: Add the android:minHeight="48dp" attribute to Button

阿神

Because you have customized the button style, but it is not the same as the system default button style, but it overrides the default style. You can change other attributes in the shape to make it the same as before. We recommend an Android Button making artifact, what you see is what you get.

迷茫

The essential reason is that the padding settings of different themes are different, so the minimum button height/width is different.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!