我有一个按钮。当我按下按钮时,我必须使文本加粗,否则正常。所以我写了粗体和正常样式。
<style name="textbold" parent="@android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">bold</item>
</style>
<style name="textregular" parent="@android:style/TextAppearance">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textStyle">normal</item>
</style>
现在我有一个button_states.xml as:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true"
style="@style/textbold" />
<item android:state_focused="false" android:state_pressed="true"
style="@style/textregular" />
<item style="@style/textregular" />
</selector>
在这个按钮的布局中,我必须让背景也是透明的…我要怎么做呢?我的布局代码是:
<Button android:id="@+id/Btn" android:background="@drawable/button_states" />
如何在我的风格中包含透明的背景?
步骤1:
在drawable中创建一个新的资源文件并复制粘贴
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#fff" android:width="2dp"/>
<corners android:radius="25dp"/>
<padding android:right="15dp" android:top="15dp" android:bottom="15dp" android:left="15dp"/>
</shape>
保存为ButtonUI(比如说)
步骤2:将UI应用到按钮xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="join the crew"
android:background="@drawable/ButtonUI"
android:textColor="#fff"/>
步骤1:
在drawable中创建一个新的资源文件并复制粘贴
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:color="#fff" android:width="2dp"/>
<corners android:radius="25dp"/>
<padding android:right="15dp" android:top="15dp" android:bottom="15dp" android:left="15dp"/>
</shape>
保存为ButtonUI(比如说)
步骤2:将UI应用到按钮xml
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="join the crew"
android:background="@drawable/ButtonUI"
android:textColor="#fff"/>