开发者

Changing Android Spinner Layout/Design

开发者 https://www.devze.com 2022-12-17 11:45 出处:网络
I am trying to modify t开发者_开发知识库he design of Spinner widget. I can change the background, but I can\'t find a way to change the arrow icon on the right side. Is there a way to do it?

I am trying to modify t开发者_开发知识库he design of Spinner widget. I can change the background, but I can't find a way to change the arrow icon on the right side. Is there a way to do it?

Thanks!


The whole thing is a single 9 patch png image. I've modified the entire look of spinners before by replacing the images. See this page: http://androiddrawableexplorer.appspot.com/

Specifically look at btn_dropdown_normal.9, btn_dropdown_pressed.9, btn_dropdown_selected.9 and btn_dropdown_disabled.9

You just need to provide your own versions of those images.


Also, you can place your "spinner bar" layout in a FrameLayout, together with the real spinner but set to invisible:

    <FrameLayout 
        android:layout_width="fill_parent"
        android:layout_height="32dip"
        >
        <Spinner
            android:id="@+id/theSpinner"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:visibility="invisible"
           />

       <RelativeLayout
         android:layout_width="fill_parent"
         android:layout_height="32dip"
         android:background="@drawable/my_background"
         android:padding="6dip"
         android:clickable="true"
         android:onClick="spinnerBarReplacementClicked"
       >
       <ImageView 
          android:id="@+id/replacementSelectImg"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"
          android:layout_alignParentRight="true"   
          android:layout_centerVertical="true"     
          android:src="@drawable/my_drawable"
          />    

       <TextView
        android:id="@+id/replacementSelectText"        
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="4dip"
        android:layout_toLeftOf="@id/replacementSelectImg"
        android:textColor="#000000"
        android:textSize="14sp"
        android:ellipsize="marquee"
        android:singleLine="true"
        />

        </RelativeLayout>     
    </FrameLayout>

and pass the clicks from your layout to the real spinner

    private Spinner mSpinner;

    mSpinner = (Spinner) findViewById(R.id.theSpinner);

    public void spinnerBarReplacementClicked(View pV){
        mSpinner.performClick();
}
0

精彩评论

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