我用来改变我的游戏中的难度,一个Spinner项目并使用字符串" Leicht"," Mittel"," Schwer"然后我把可绘制的文件作为背景,但是当我启动应用程序时,我可以在后台看到我用于微调器的字符串..我可以隐藏字符串吗?我只看到可绘制的背景?
schwierigkeitsgradAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, new String[] {" Leicht"," Mittel"," Schwer"});
schwierigkeitsgradAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
schwierigkeitsgrad.setAdapter(schwierigkeitsgradAdapter);
和xml代码:
<Spinner
android:id="@+id/schwierigkeitsgrad"
android:layout_gravity="center_horizontal"
android:layout_marginTop="360dp"
android:background="@drawable/btnschwierigkeit"
android:textAlignment="center"
android:layout_width="220dp"
android:layout_height="90dp"
android:gravity="center_vertical|start"
android:foregroundGravity="center_vertical"
android:spinnerMode="dialog" />
答案 0 :(得分:1)
尝试此选项以在选择期间隐藏微调文本:
Spinner spinner = (Spinner)findViewById(R.id.your_spinner);
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// hide selection text
((TextView)view).setText(null);
// if you want you can change background here
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
要显示微调器项,请使用:
String[] test=new String[]{"easy", "medium", "heavy"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(yourActivity.this,android.R.layout.simple_spinner_item, test);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
schwierigkeitsgrad.setAdapter(adapter);