// 上面gravity属性的参数:center为居中,center_horizontal为水平居中,center_vertical为垂直居中
2、在下面建立一个xml文件:selector.xml
代码如下:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/normal" android:state_pressed="false"/>
<item android:drawable="@drawable/pressed" android:state_pressed="true"/>
</selector>
然后在value文件夹下的string.xml文件里添加:
代码如下:
<drawable name="normal">#ff6501</drawable>
<drawable name="pressed">#a44100</drawable>
最后为button添加:
代码如下:
<Button
android:layout_marginTop="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="打印"
android:id="@+id/printer"
android:textColor="@android:color/white"
android:background="@drawable/selector"
/>