在android中我定义了一个布局如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:columnCount="4"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar_setting"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"/>
<Spinner
android:id="@+id/settings_interval"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="@string/spinner_title"/>
...
但是有些原因导致在我开始相应的活动时没有显示微调器的android:promp
文本。为了完整起见,这是一项活动:
public class SettingsActivity extends AppCompatActivity implements AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
// Set toolbar, allow going back.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_setting);
//toolbar.setDisplayHomeAsUpEnabled(true);
//toolbar.setTitle("Settings");
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("Settings");
Spinner spinner = (Spinner) findViewById(R.id.settings_interval);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.listValues, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
}
}
答案 0 :(得分:1)
这是来自Spinner
类的代码:
public void setPromptText(CharSequence hintText) {
// Hint text is ignored for dropdowns, but maintain it here.
mHintText = hintText;
}
在dropDown模式下看起来像spinner忽略提示。尝试设置android:spinnerMode="dialog"
进行检查。
此外,您可以查看here来解决此问题。