我无法使工作成为简单的android微调器。我在互联网上跟踪了许多示例,但没有人适合我。
这是我在xml中所做的:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center">
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:theme="@style/ThemeOverlay.AppCompat.Light"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
在我的java类中:
public class PreferencesActivity extends AppCompatActivity {
Spinner spinner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preferences);
spinner = (Spinner) findViewById(R.id.spinner);
ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.language_list, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
@Override
public void onResume(){
super.onResume();
setContentView(R.layout.preferences);
}
}
在我的xml res / string中:
<resources>
<string-array name="language_str">
<item>Language</item>
<item>Langue</item>
<item>Lingua</item>
<item>Idioma</item>
</string-array>
<string-array name="language_list">
<item>English</item>
<item>Francais</item>
<item>Italiano</item>
<item>Espanol</item>
</string-array>
</resources>
当我调试应用程序(使用实际设备)时,微调器根本不显示,就像代码从不执行一样。我读到有关旋转的“更改背景颜色”,但似乎什么也没有发生。我尝试在xml文件中添加关键字“ entries”,但没有任何反应。
可能是什么问题呢?我哪里错了?谢谢,马可。
从onResume()方法中删除以下行将解决您的问题
setContentView(R.layout.preferences);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句