2013-07-02 40 views
5

Tôi đang sử dụng trình quay tròn và nó sẽ mở ra như một hộp thoại. Tôi cần spinner để mở như trình đơn thả xuống.spinner hiển thị như hộp thoại

Dưới đây là file xml

<Spinner 
android:id="@+id/sp_countrycode_issue_coupon" 
android:layout_width="60dp" 
android:layout_height="40dp" 
android:layout_gravity="center" 
android:layout_marginLeft="3dp" 
android:layout_weight="1" 
android:background="@drawable/img_small_box_green" 
android:dropDownSelector="@drawable/img_small_box_green" 
android:gravity="right|center" 
android:textAlignment="center" /> 

Đây là mã

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
      this, R.array.country_code, 
      android.R.layout.simple_spinner_item); 

adapter.setDropDownViewResource(R.layout.spinner_textview); 
sp_country_code.setAdapter(adapter); 

tôi đăng hình ảnh của tôi rống lên như xem và spinner xem hiển thị của tôi. Nhưng tôi cần những spinner được hiển thị như hình thứ ba

Here is my layout Spinner displays in this way But I need in this format

+0

Bạn đang thử nghiệm phiên bản Android nào? – Nirali

+0

hiện tại là Android 4.1. Nhưng điều tương tự cũng hiển thị trên phiên bản 2.3 và bên dưới –

Trả lời

3

Đối với spinner thông tin thả xuống mà bạn thể hiện trong Hình 3 được áp dụng từ phiên bản 3.0 trở lên. Đối với các phiên bản trước như 2.2 và 2.3, phiên bản này sẽ mở ra như hộp thoại. Nó sẽ tự động hiển thị menu thả xuống trong các phiên bản ở trên 2.3

Kiểu sẽ tự động được thêm nếu bạn chọn phiên bản Android 4.0 trở lên.

<!-- 
    Base application theme for API 14+. This theme completely replaces 
    AppBaseTheme from BOTH res/values/styles.xml and 
    res/values-v11/styles.xml on API 14+ devices. 
--> 
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault.Light.DarkActionBar"> 
    <!-- API 14 theme customizations can go here. --> 
</style>  

enter image description here

đang refrence

severitySpinner = (Spinner) findViewById(R.id.spinnerSeverity); 
    severityAdapter = ArrayAdapter.createFromResource(this, 
      R.array.severity_arrays, android.R.layout.simple_spinner_item); 
    severityAdapter 
      .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
    severitySpinner.setAdapter(severityAdapter); 

Sửa

<application 
     android:icon="@drawable/appicon" 
     android:label="Test" 
     android:theme="@style/AppTheme" > 
+0

Trước đây chủ đề của tôi được đặt thành android: Theme.Light bây giờ tôi đã thay đổi nó thành android: Theme.DeviceDefault.Light.DarkActionBar và tôi cảm thấy không có sự khác biệt nhưng chỉ có một là radiobuttons tôi có thể nhìn thấy trên menu thả xuống. Hiện tại tôi đang sử dụng Android 4.1 –

+0

Bạn đã thay đổi phần mã chưa? – Nirali

+0

có, tôi đã thực hiện các thay đổi trong mã ngay cả –

0

Chỉ cần thay đổi mã như thế này:

ArrayAdapter<String> spinnerMenu = new ArrayAdapter<String>(
        RegisterActivity.this, R.layout.spinner_item, list); 
      // TODO Auto-generated method stub 
      spinnerMenu 
        .setDropDownViewResource(android.R.layout.simple_list_item_single_choice); 

      country.setAdapter(spinnerMenu); 
      country.getSelectedItemPosition(); 
+0

Hiển thị của nó như "R.layout.spinner_textview" thay vì "R.layout.spinner_item" –

+0

Nhưng tôi đã tạo cho văn bản tùy chỉnh spinner ... vì vậy bạn vừa mới đặt xml của mình tập tin thay vì nó .... chỉ cần không có gì và có được một thả xuống thích hợp –

2

trong manifest theme thay đổi tập tin để android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" và theo kiểu tệp xml đặt cho spinner style="@style/MyDropDownNav" và trong kiểu tệp thêm kiểu.

<!-- style the list navigation --> 
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner"> 
    <item name="android:popupBackground">@drawable/bg_popup</item> 
    <item name="android:dropDownSelector">@drawable/top_layout</item> 
</style> 
+0

Nó được hiển thị trong menu thả xuống nhưng làm thế nào để thoát khỏi các nút radio. –

+0

Tôi đã có thể nhận được danh sách thả xuống nhưng cách xóa nút radio trên các mục danh sách –

4

trễ nhưng có thể hữu ích cho người khác, bạn có thể chỉ cần đặt các spinnerMode để thả xuống:

android:spinnerMode="dropdown" 

khác, nếu bạn quyết định bạn tưởng tượng một sự thay đổi và muốn thoại trong tương lai chỉ cần thay đổi chế độ thoại!

+0

Không thực sự bro. cấp API hoạt động của spinnermode 11 ở trên –

Các vấn đề liên quan