我Spinner喜欢这个:
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner1"
android:background="@drawable/spinner_bg"
android:popupBackground="@drawable/spinner_bg"/>
Run Code Online (Sandbox Code Playgroud)
这是spinner_bg.xml:
<item>
<layer-list>
<item>
<shape>
<gradient
android:startColor="#ffffff"
android:centerColor="#111111"
android:endColor="#000000"
android:angle="-90" />
<stroke
android:width="2dp"
android:color="#ffffff" />
<corners
android:radius="2dp" />
<padding
android:left="10dp"
android:right="10dp"/>
</shape>
</item>
<item >
<bitmap
android:gravity="right"
android:src="@android:drawable/arrow_down_float" />
</item>
</layer-list>
</item>
Run Code Online (Sandbox Code Playgroud)
这是Custom spinner的代码:
ArrayAdapter<ClassId> adapter = new ArrayAdapter<ClassId>(getActivity(),
R.layout.list_id, idList);
adapter.setDropDownViewResource(R.layout.list_id_select);
Run Code Online (Sandbox Code Playgroud)
这是list_id.xml的布局:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:singleLine="true"
android:ellipsize="end"
android:textColor="#ff0004"
android:textSize="14sp"
android:paddingTop="10dp"
android:paddingBottom="10dp"/>
Run Code Online (Sandbox Code Playgroud)
这是list_id_select.xml的布局:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAllCaps="true"
android:singleLine="true"
android:ellipsize="end"
android:textColor="#0004ff"
android:textSize="14sp"
android:checked="true" …Run Code Online (Sandbox Code Playgroud) android textview android-spinner android-checkbox drop-down-menu
我试图让我的微调器作为Action Bar下拉列表项目工作,但我似乎无法实现它,在搜索Google之后没有很多教程.我认为它与.setListNavigationCallbacks(); 代码行,我只是不知道如何从这一行开始工作.
// setup action bar for spinner
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
bar.setListNavigationCallbacks();
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.tools_array_stopwatch, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
switch (arg2) {
case 0:
break;
case 1:
Intent countdown = new Intent(this, CountdownActivity.class);
startActivity(countdown);
break;
default :
break;
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
Run Code Online (Sandbox Code Playgroud) 我正在为我的Android应用程序开发一个帐户管理活动,但是我很难弄清楚为什么来自微调器的setSelection()方法不会触发附加到所述Spinner的OnItemSelectedListener.
这就是我目前所拥有的;
onCreate()方法:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_management);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
retreiveLanguage();
initializeUI();
// Vérification si l'usager est déjà connecté
Globals appState = ((Globals) this.getApplication());
boolean userLoggedIn = appState.isUserLoggedIn();
boolean userInfoAvailable = appState.isUserInfoAvailable();
if (userLoggedIn && userInfoAvailable) {
fillUI();
}
}
Run Code Online (Sandbox Code Playgroud)
来自initializeUI()方法的相关行,该方法在Activity的创建中调用,该方法显示Spinner与Listener的绑定:
/** OnItemSelectedHandler for the Country Spinner */
mCountrySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Log.i(TAG, "onCountrySelected() was called, position : " + pos);
mProvinces = new ArrayList<String>();
mProvincesCode …Run Code Online (Sandbox Code Playgroud) 我创建了自己的自定义微调器,我可以在它实现的"自定义和库视图"中访问它View.但是,问题是当从我的调色板中拖动我的自定义微调器以在我的中使用它时main.xml,它会抛出"未处理的事件循环异常".我不知道我的错误在哪里.
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:pref="http://schemas.android.com/apk/res/com.myspinner"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.myspinner.Myspinner
android:id="@+id/myspinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
pref:MyEntries="@array/testarray" />
Run Code Online (Sandbox Code Playgroud)
MySpinnerattributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MySpinner">
<attr name="MyEntries" format="reference"/>
</declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)
spinnerlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:text="@string/large_text" android:gravity="center"/>
Run Code Online (Sandbox Code Playgroud)
Myspinner.java
public class Myspinner extends Spinner{
LayoutInflater inflater;
CharSequence cs[]={"MySpinner"};
String s[]={"MySpinner"};
View row;
TextView txt;
public Myspinner(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setAttributes(attrs);
this.setAdapter(new MyAdapter(this.getContext(), R.layout.spinnerlayout,s));
}
public Myspinner(Context …Run Code Online (Sandbox Code Playgroud) android custom-attributes custom-component android-arrayadapter android-spinner
我正在尝试设置微调器弹出窗口的背景颜色,但我尝试过的所有内容都无法正常工作.
这是微调控件:
<Spinner
android:id="@+id/myspinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@null"
android:drawSelectorOnTop="true" />
Run Code Online (Sandbox Code Playgroud)
当我点击它时,它会显示一个带有白色背景的弹出窗口,我想改变它.
我用来填充弹出窗口的xml行是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/list_selector"
android:paddingBottom="@dimen/padding_medium"
android:layout_marginBottom="@dimen/padding_medium"
android:orientation="vertical">
..........
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
和drawable background list_selector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Pressed -->
<item
android:state_pressed="true"
android:drawable="@color/green" /> <!-- @drawable/tab_press -->
<!-- Selected -->
<item
android:state_selected="true"
android:drawable="@color/green" /> <!-- @drawable/tab_press -->
</selector>
Run Code Online (Sandbox Code Playgroud)
向上面的xml添加默认状态是可以的,但是微调器主控件显示具有该背景颜色的项目,我不希望这样.
我尝试过的另一件事是在styles.xml中将应用程序背景颜色设置为黑色
<style name="AppTheme" parent="android:Theme.Light">
<item name="android:background">#000000</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:typeface">sans</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这也会覆盖弹出背景,但它具有不良的附带效果.有没有办法以简单的方式实现这一目标?
谢谢!
PS:我正在使用API级别10(2.3.3),并且该属性android:popupBackground不存在.
android background popup android-2.3-gingerbread android-spinner
我想在外部点击时隐藏微调器提示弹出窗口.如果提示弹出窗口打开并且用户按下主页键活动将最小化,因此当用户再次打开应用程序时,提示弹出窗口应该消失.
有没有办法实现这一目标.谢谢
编辑: - 不自定义提示弹出窗口.所以我无法隐藏它们onPause或onResume方法.
我从SQLite数据库获取数据并将它们分配给数据对象.我正在使用自定义微调器适配器(器具SpinnerAdapter)将它们放在微调器中,以便覆盖getItem()和getItemId()方法.但是,android.R.layout.simple_spinner_dropdown_item显示不正确(我的Galaxy Tab 2 10.1截图):

相比之下,这是一个从数组中填充的微调器R.array(正确的外观/大小):

完成此代码:
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.quote_prices, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)
我无法通过实现/扩展某种适配器来获得这种外观(我也试过延伸BaseAdapter无济于事).这是我的微调器适配器的代码:
public class MySpinnerAdapter implements SpinnerAdapter {
private Context context;
/**
* The internal data (the ArrayList with the Objects).
*/
private List<? extends BaseDO> data;
public MySpinnerAdapter(Context context, List<?extends BaseDO> data){
this.context = context;
this.data = data;
}
/**
* Returns the Size of the ArrayList
*/
@Override
public int getCount() {
return …Run Code Online (Sandbox Code Playgroud) 首先,我知道这次被问了好几次,但是在较新的android平台上,看起来建议的解决方案不起作用(正如其他人所说的那样).我需要我的微调器仍然调用OnItemSelected,即使用户选择了两次相同的项目.我已经设法找到这个应该做的伎俩:
public class NDSpinner extends Spinner {
private int lastSelected = 0;
private static Method s_pSelectionChangedMethod = null;
static {
try {
Class noparams[] = {};
Class targetClass = AdapterView.class;
s_pSelectionChangedMethod = targetClass.getDeclaredMethod("selectionChanged", noparams);
if (s_pSelectionChangedMethod != null) {
s_pSelectionChangedMethod.setAccessible(true);
}
} catch( Exception e ) {
Log.e("Custom spinner, reflection bug:", e.getMessage());
throw new RuntimeException(e);
}
}
public NDSpinner(Context context) {
super(context);
}
public NDSpinner(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NDSpinner(Context context, AttributeSet attrs, int defStyle) { …Run Code Online (Sandbox Code Playgroud) 我在项目中使用appcompat v21,但我不喜欢它默认带来的新spinner.这个新的旋转器只带有一个向下的小箭头,指示它的存在.我更喜欢在4.x版本的android中使用的旧微调器,它带有类似EditText的功能,用于强调小部件的内容和右下角的箭头.
如何在使用appcompat v21的同时实现这种微调器的风格?
不受欢迎的微调风格:
不受欢迎的微调器的照片:

想要的微调器的照片:

我的所有微调器都是相互连接的,它们不是独立的,我想根据spinner1中的选择显示spinner2和spinner3中的选项(我的意思是基于用户在spinner1中选择的类别)
在onCreate我将数据填充到Spinners中,但是在spinner2和spinner3中我得到的数据属于CategoryB,而它们只能填充CategoryA数据.
那我的错误在哪里?这是我的JSON解析代码:
categoryArrayList = new ArrayList<Category>();
cArrayList = new ArrayList<String>();
...................................
// Array Level 1 --- START
JSONArray jarray = jsono.getJSONArray("categories");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Category language = new Category();
language.setName(object.getString("category_name"));
Log.d("category_name::-", object.getString("category_name"));
language.setTypeArrayList(typeArrayList);
categoryArrayList.add(language);
cArrayList.add(categoryArrayList.get(i).getName());
// Array Level 1 --- END
// Array Level 2 --- START
JSONArray jsarray = object.getJSONArray("types");
typeArrayList = new ArrayList<Type>();
tArrayList = new ArrayList<String>();
for (int j = 0; j < …Run Code Online (Sandbox Code Playgroud)