我的应用程序我想要以下类型的Spinner Dropdown视图。 对于这种类型的微调视图。我写了这段代码。
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.spinner, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_obj.setAdapter(adapter);
我是从http://developer.android.com/guide/topics/ui/controls/spinner.html得到的 但我得到的是,
请为我提供最好的方法....
答案 0 :(得分:30)
有点复兴旧帖子,但接受的答案远非理想。执行此操作的正确方法是在布局xml中将Spinner设置为下拉模式:
<Spinner
android:id="@+id/my_spinner"
...
android:spinnerMode="dropdown"/>
可用选项包括“对话框”和“下拉列表”。
答案 1 :(得分:8)
您的应用程序在旧主题上运行。
如果你使用android 4.2设置android应用程序主题(在清单文件中)
android:theme="@android:style/Theme.Holo.Light"
OR
android:theme="@android:style/Theme.Holo.Light.DarkActionBar"
答案 2 :(得分:2)
可能是你在4.0以下运行,4.0会显示你的图像下拉列表
答案 3 :(得分:1)
您可以使用如下弹出窗口:
spinner=(EditText)findViewById(R.id.txt_Spinner);
spinner.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
p = new Point();
p.x = location[0]+(v.getHeight());
p.y = location[1]+v.getHeight();
if (p != null)
showPopup(statusActivity.this, p);
System.out.println("show popup");
}
});
// The method that displays the popup.
private void showPopup(final Activity context, Point p) {
int popupWidth = 300;
int popupHeight = 500;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
// Creating the PopupWindow
popup = new PopupWindow(context);
popup.setContentView(layout);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
// Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
int OFFSET_X = 00;
int OFFSET_Y = 00;
// Clear the default translucent background
popup.setBackgroundDrawable(new BitmapDrawable());
// Displaying the popup at the specified location, + offsets.
popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
((TextView)layout.findViewById(R.id.textView2)).setClickable(true);
((TextView)layout.findViewById(R.id.textView3)).setClickable(true);
((TextView)layout.findViewById(R.id.textView4)).setClickable(true);
((TextView)layout.findViewById(R.id.textView5)).setClickable(true);
((TextView)layout.findViewById(R.id.textView6)).setClickable(true);
((TextView)layout.findViewById(R.id.textView7)).setClickable(true);
((TextView)layout.findViewById(R.id.textView8)).setClickable(true);
((TextView)layout.findViewById(R.id.textView9)).setClickable(true);
}
and popup.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/popup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/popup_bg"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
style="@style/text_orange_heading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Select Status"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/textView2"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Sleeping"
android:text="Sleeping" />
<TextView
android:id="@+id/textView3"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Available"
android:text="Available" />
<TextView
android:id="@+id/textView4"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Busy"
android:text="Busy" />
<TextView
android:id="@+id/textView5"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="At work"
android:text="At work" />
<TextView
android:id="@+id/textView6"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="Battery charge low"
android:text="Battery charge low" />
<TextView
android:id="@+id/textView7"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="In meeting"
android:text="In meeting" />
<TextView
android:id="@+id/textView8"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="TMS me later"
android:text="TMS me later" />
<TextView
android:id="@+id/textView9"
style="@style/text_blue_contains"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:onClick="onClick"
android:clickable="true"
android:drawableBottom="@drawable/line_white"
android:tag="At the toilet"
android:text="At the toilet" />
<EditText
android:id="@+id/textCustomize"
style="@style/text_blue_contains"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:tag="Customize"
android:text="Customize" />
</LinearLayout>
答案 4 :(得分:1)
对于GUI使用HoloEverywhere。 https://github.com/Prototik/HoloEverywhere HoloEverywhere是最好的方式,如果你想在旧版Android 4.0上使用Holo主题。
对于下拉列表,在Stephen Kidson提到的布局中使用android:spinnerMode =“dropdown”。
答案 5 :(得分:-3)