我使用的操作欄福爾摩斯與導航模式NAVIGATION_MODE_LIST與定製微調適配器。操作欄福爾摩斯NAVIGATION_MODE_LIST - dropdownListPreferredItemHeight忽略
問題是,下拉列表視圖看起來受到擠壓,項目的高度顯示爲具有wrap_content而不是固定的高度。 (this is how it looks)
按照* abs_themes *,高度應48dip:
<item name="dropdownListPreferredItemHeight">48dp</item>
如果我使用它正常工作的資源創造了一個非自定義微調適配器,我缺少什麼?這裏一個樣本代碼,我寫道:
MainActivity.java
package com.example.themetest;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.OnNavigationListener;
import com.actionbarsherlock.app.SherlockActivity;
public class MainActivity extends SherlockActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
final String[] choices = {"Android", "iOS", "RIM"};
CustomSpinnerAdapter customSpinnerAdapter = new CustomSpinnerAdapter(MainActivity.this, android.R.id.text1, choices);
actionBar.setListNavigationCallbacks(customSpinnerAdapter, new OnNavigationListener() {
@Override
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
Toast.makeText(MainActivity.this, choices[itemPosition], Toast.LENGTH_SHORT).show();
return false;
}
});
// this works properly
// actionBar.setListNavigationCallbacks(ArrayAdapter.createFromResource(this, R.array.sections, R.layout.sherlock_spinner_dropdown_item),
// new OnNavigationListener() {
// public boolean onNavigationItemSelected(int itemPosition, long itemId) {
// return false;
// }
// });
}
private class CustomSpinnerAdapter extends ArrayAdapter<String> implements SpinnerAdapter {
private LayoutInflater layoutInflater;
public CustomSpinnerAdapter(Context context, int textViewResourceId, String[] values) {
super(context, textViewResourceId, values);
this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return initView(position, convertView);
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return initView(position, convertView);
}
private View initView(int position, View convertView) {
if (convertView == null) {
convertView = layoutInflater.inflate(R.layout.sherlock_spinner_dropdown_item, null);
}
((TextView) convertView.findViewById(android.R.id.text1)).setText(getItem(position));
return convertView;
}
}
}
styles.xml
<resources>
<style name="Theme.AppTheme" parent="Theme.Sherlock.Light" />
</resources>
的manifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.AppTheme" >
<activity
android:name="com.example.themetest.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
是什麼'AppTheme'從延長? – 2013-04-03 22:12:56
我通過創建一個類'public class CustomCursorAdaptor extends SimpleCursorAdapter'來做同樣的事情,爲什麼你要使用'CustomSpinnerAdaptor'? – Mangusto 2013-04-03 22:16:27
@JakeWharton Theme.Sherlock.Light – gwa 2013-04-03 22:19:23