爲Android開發時,我面臨的一個常見問題涉及按鈕資產。Android按鈕資產
問題:UI設計者需要特定的按鈕外觀(通常只是與標準Android Holo Button不同的顏色)。
我該如何做到這一點?我只是不知道正確的方式去了解它...
我應該
a)創建一個十六進制顏色代碼按鈕,有一個形狀/選擇
B)有UI設計師放下我的drawables按鈕和可繪製的選定狀態?
爲Android開發時,我面臨的一個常見問題涉及按鈕資產。Android按鈕資產
問題:UI設計者需要特定的按鈕外觀(通常只是與標準Android Holo Button不同的顏色)。
我該如何做到這一點?我只是不知道正確的方式去了解它...
我應該
a)創建一個十六進制顏色代碼按鈕,有一個形狀/選擇
B)有UI設計師放下我的drawables按鈕和可繪製的選定狀態?
如果你可以使用原生繪圖(形狀,漸變,圓形邊框等)來設置按鈕的風格,那就去做那個,否則你將需要使用9-補丁繪製。
在繪製文件夾中創建名爲custom_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" >
<shape>
<gradient
android:startColor="@color/actionButtonColor2"
android:endColor="@color/actionButtonColor1"
android:angle="270" />
<stroke
android:width="2dp"
android:color="@color/activeBorder" />
<corners
android:radius="5dp" />
</shape>
</item>
<item android:state_focused="true" >
<shape>
<gradient
android:startColor="@color/actionButtonColor1"
android:endColor="@color/actionButtonColor2"
android:angle="270" />
<stroke
android:width="2dp"
android:color="@color/highlightBorder" />
<corners
android:radius="5dp" />
</shape>
</item>
<item android:state_enabled="false">
<shape>
<gradient
android:startColor="@color/disabledStartColor"
android:endColor="@color/disabledEndColor"
android:angle="270" />
<stroke
android:width="2dp"
android:color="@color/inactiveBorder" />
<corners
android:radius="5dp" />
</shape>
</item>
<item>
<shape>
<gradient
android:startColor="@color/actionButtonColor1"
android:endColor="@color/actionButtonColor2"
android:angle="270" />
<stroke
android:width="2dp"
android:color="@color/activeBorder" />
<corners
android:radius="5dp" />
<padding
android:bottom="10dp"
android:top="10dp"
android:left="10dp"
android:right="10dp" />
</shape>
</item>
</selector>
然後一個XML文件,在活動
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/up"
android:id="@+id/buttonUp1"
android:background="@drawable/custom_button2"/>