Android的GridView中的選中圖示後圖示的背景顏色
1.首先在GridView元件中新增android:listSelector="@android:color/transparent",表示選中圖示後顏色是透明的(給使用者的感覺就是根本不曉得點沒點圖示)
2.在drawable資料夾下建立item選中,獲取焦點,預設,這些狀態和顏色的對應關係的配置檔案
3.在GridView中item的佈局檔案中引入第二步建立的配置檔案android:background="@drawable/home_selector"
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<GridView
android:id="@+id/haha"
android:numColumns="3"
android:listSelector="@android:color/transparent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</GridView>
</LinearLayout>
item.xml(GridView中的元件的佈局配置檔案)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/seletced"
android:orientation="vertical" ><!--android:background="@drawable/seletced"匯入最後那個狀態和顏色之間對應關係的配置檔案 -->
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/weishi"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="哈哈哈哈"
/>
</LinearLayout>
在valuse資料夾下建立顏色的資原始檔(就是顏色名稱和顏色的值對應)
color.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="trans">@android:color/transparent</color><!-- 透明 -->
<color name="green">#33FF33</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/green" android:state_pressed="true"/><!-- @color表示的是color.xml green表示name=green的標籤裡的屬性 -->
<!-- pressed -->
<item android:drawable="@color/green" android:state_focused="true"/>
<!-- focused -->
<item android:drawable="@color/trans"/>
<!-- default -->
</selector>
在佈局檔案中引入 狀態和顏色之間對應的xml。
在狀態和顏色之間對應的xml中引用color.xml中定義的顏色(這一步可換成圖片引用,因為當item android:drawable="@drawable/button_green_on"時,表示引用的是一張圖片,也就是說按下的時候是一張圖片,鬆開的時候是另一張圖片,這時候是圖片之間的切換了而不是顏色之間的切換了。)
相關文章
- svg 圖示設定背景顏色SVG
- Android的標題欄,狀態列圖示文字顏色及背景動態變化Android
- 圖示任意改變顏色
- iconfont的使用,阿里向量相簿的引用,配置,改變圖示大小和圖示顏色阿里
- linux中顯示有顏色的字元......Linux字元
- CSS 中的顏色、背景和剪下CSS
- echars legend未選中、點選後的顏色修改
- 管理Mac電腦選單欄中的圖示Mac
- springboot中圖示的定製Spring Boot
- Activity背景顯示app圖示APP
- CSS設定選中網頁文字時的背景和顏色CSS網頁
- ReSharper 顯示使用的顏色
- 如何修改CAD夢想畫圖繪圖視窗的背景顏色繪圖
- android關鍵字特殊顏色顯示的實現Android
- js將選擇的圖片顯示在img中JS
- wpf 中阿里圖示庫的使用阿里
- react native拖動上方顯示值,改變背景顏色的sliderReact NativeIDE
- 直播原始碼網站,任意更改底部圖示顏色原始碼網站
- ECHARTS-折線圖不顯示資料 控制折線圖顏色Echarts
- Mac技巧|如何管理Mac電腦選單欄中的圖示Mac
- 關於vue打包後scss檔案中背景圖片不顯示問題VueCSS
- Dreamweaver製作滑鼠經過圖示改變顏色教程
- Mac更改資料夾圖示顏色軟體:Color FolderMac
- Mac資料夾圖示顏色修改工具Color Folder MacMac
- 改變SVG圖的顏色SVG
- 設定toast的字型顏色和背景顏色AST
- Win10 1903系統中顯示器顯示顏色垂直條紋的解決方法Win10
- echarts 柱狀圖的選中模式實現-被選中變色和再次選中為取消變色Echarts模式
- 視覺化學習:圖形系統中的顏色表示視覺化
- 擴充套件EasyUI在頁面中馬上顯示選中的本地圖片套件UI地圖
- Android圖示適配Android
- 天地圖修改主題顏色修改背景色地圖
- Android中呼叫攝像頭拍照儲存,並在相簿中選擇圖片顯示Android
- JavaScript點選設定背景顏色的選項卡程式碼JavaScript
- echart map圖示切換多選,單選,預設選中
- web專案中圖示的前端處理方案Web前端
- 小程式button背景顯示圖片
- Android系統耳機圖示顯示Android
- 為雷達圖中不同系列的資料使用不同的顏色