Button自定義背景顏色及圓角

2021-07-22 10:13:28 字數 913 閱讀 3147

1、先在資源檔案colors.xml中定義按下和常規的顏色,eg:

#99ccff

#0099ff

2、在drawable資料夾下建立2個檔案 ,分別為按下和常規的樣式,及設定按鈕的圓角,eg:

常規顯示的顏色:

<?xml version="1.0" encoding="utf-8"?>

xmlns:android="" >

android:color="@color/btn_color_normal"/>

android:radius="5dip"/>

shape>

按鈕被按下時顯示的顏色:

<?xml version="1.0" encoding="utf-8"?>

xmlns:android="" >

android:color="@color/btn_color_press"/>

android:radius="5dip"/>

shape>

3、在drawable中建立乙個selector 檔案,然後引用上面2個檔案。

<?xml version="1.0" encoding="utf-8"?>

xmlns:android="">

android:drawable="@drawable/btn_color_press"

android:state_pressed="true">

item>

android:drawable="@drawable/btn_color_nomral">

item>

selector>

4、最後在按鈕中用background使用上面這個selector 檔案。

自定義樣式View 二 自定義Button

android中自帶的 button 樣式比較醜,為了美化 button 可使用一下方法。實現效果如下 自定義 button 實現效果 1.自定義button 背景選擇器 2.自定義buton 素材 3.自定義button 背景 我們不是牛逼的程式設計師,我們只是程式開發中的墊腳石。我們不傳送紅包,...

MFC 改變Eidt背景顏色 自定義類

新建乙個mfc工程並新增乙個新類,這裡我的叫做ccoloredit 父類是cedit,在新類中重寫 wm ctlcolor事件,注意是 不是wm ctlcolor,在函式中新增 hbrush ccoloredit ctlcolor cdc pdc,uint nctlcolor return null...

自定義cell背景和選中時顏色

下面兩句 即可 cell顏色設定為白色 self.backgroundview uiimageview alloc initwithimage uiimage imagewithcolor uicolor whitecolor cell選中的顏色是淡藍色 self.selectedbackgroun...