更改 Android Spinner 的布局/设计

12

我正在尝试修改Spinner组件的设计。我可以更改背景,但是找不到一种方法来更改右侧箭头图标。有什么方法可以做到吗?

谢谢!

2个回答

12

整个东西是一个单独的9 patch png图像。我之前曾通过替换图片修改过旋转框的整体外观。请参见此页面:http://androiddrawableexplorer.appspot.com/

具体来说,请查看btn_dropdown_normal.9、btn_dropdown_pressed.9、btn_dropdown_selected.9和btn_dropdown_disabled.9这些图片。

您只需要提供自己版本的这些图片即可。


如何从android.jar更改这个。你能给我任何想法吗? 谢谢 - BIBEKRBARAL
猜测那个网站已经崩溃了,这里有另一个提供相同内容的网站:http://androiddrawableexplorer.appspot.com/。 - Mark B

0
此外,您可以将“旋转条”布局与真正的旋转器一起放置在FrameLayout中,但将其设置为不可见状态:
    <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>

将您布局中的点击事件传递给实际的旋转控件

    private Spinner mSpinner;

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接