开发者

Android GridView Selected Item Background

My GridView Not Show Pressed and Focused Selector My Code is Below.

myhomegrid.xml

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/gwMenu"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:columnWidth="90dp"
android:stretchMode="columnWidth"
android:gravity="center" 
android:drawSelectorOnTop="true"
android:listSelector="@layout/grid_selector"

     />

grid_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/pressedback" />
<item android:state_window_focused="false" android:drawable="@drawable/focusedback" />
<item android:state_window_focused="true" android:drawable="@drawable/focusedback" />
</selector>

menu.xml

<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/widget44"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:orientation="vertical"
android:layout_x="201px"
 android:layout_y="165px"
 android:gravity="center_horizontal">
 <ImageView
 android:id="@+id/icon_image"
android:layout_w开发者_运维问答idth="wrap_content"
android:layout_height="wrap_content">
 </ImageView>
<TextView
android:id="@+id/icon_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:textColorHighlight="#656565">
</TextView>
</LinearLayout>

Focused Image

Android GridView Selected Item Background

Pressed Image

Android GridView Selected Item Background

I want to seletor like below image:

Android GridView Selected Item Background


You should place your grid_selector.xml in the drawable folder and then reference it by:

android:listSelector="@drawable/grid_selector"


You should correct your selector, like this

<selector xmlns:android="http://schemas.android.com/apk/res/android">
   <item android:state_pressed="true" android:drawable="@drawable/pressedback" />
   <item android:state_focused="true" android:drawable="@drawable/focusedback" />
   <item android:state_selected="true" android:drawable="@drawable/focusedback" />
</selector>

UPD: My bad, you don't need clickable and focusable aatributes for GridView

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜