我能够使用纯XML(无图像)按照自己的喜好设置按钮。以下是它的外观:
shape_button_normal_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="7dip"/>
<gradient android:startColor="@color/blue_start" android:endColor="@color/blue_end" android:angle="270" />
<stroke android:width="1dip" android:color="#80036990" />
<padding android:left="5dip" android:right="5dip" android:top="7dip" android:bottom="7dip"/>
</shape>
类似于我描述的其他形状的按下/禁用/等
这是我的selector_button_blue:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/shape_button_normal_blue" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="@drawable/shape_button_disabled" />
<item android:state_pressed="true"
android:drawable="@drawable/shape_button_selected" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/shape_button_focused_blue" />
<item android:state_enabled="true"
android:drawable="@drawable/shape_button_normal_blue" />
<item android:state_focused="true"
android:drawable="@drawable/shape_button_normal_blue" />
<item android:drawable="@drawable/shape_button_disabled" />
</selector>
最后我的风格:
<style name="MyBlueButton" parent="@android:style/Widget.Button">
<item name="android:background">@drawable/selector_button_blue</item>
<item name="android:layout_marginLeft">1dp</item>
<item name="android:layout_marginRight">1dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">18dp</item>
<item name="android:textStyle">bold</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">fill_parent</item>
</style>
我正在使用那些按钮,文字很好。快乐而自豪:)
现在我需要在上面加上图标。我看到有顶部/底部/左/右但它没有做我需要的。我在这里想念什么?我如何让它变得美好和集中?
<Button style="@style/MyBlueButton" android:layout_marginTop="0dp" android:text="" android:layout_width="0dp" android:layout_weight="0.15"
android:drawableTop="@drawable/ic_accept"/>
答案 0 :(得分:2)
使用imagebutton,类似于Edited
>
<ImageButton
android:id="@+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_accept"
android:background="@drawable/selector_button_blue"
/>