我有一个关于如何从 Android 中的 XML 布局获取视图的问题?我正在使用微调器,它现在可以保存选定的微调器值。我想从 content_doa.xml 布局中获取 ID 为 titleTextView 的 TextView 视图。我试过使用 LayoutInflater 但它不起作用,它还没有产生任何效果。你能帮我解决问题吗?
干得好:
字体设置.java
public class FontSettings extends AppCompatActivity {
private Spinner spinner1, spinnerLatin;
private SharedPreferences mMyPrefs;
private SharedPreferences.Editor mMyEdit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_font);
// toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); //this line shows back button
//Display data size teks arab in dropdown list spinner
final Spinner spinnerBackgroundChange = (Spinner)findViewById(R.id.spinner1);
final LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final SharedPreferences sharedPref = getSharedPreferences("My_Prefs", 6);
ArrayAdapter<CharSequence> spinnerArrayAdapter = ArrayAdapter.createFromResource(this, R.array.country_arrays, android.R.layout.simple_spinner_item);
spinnerArrayAdapter.setDropDownViewResource(R.layout.textview_with_background);
spinnerBackgroundChange.setAdapter(spinnerArrayAdapter);
spinnerBackgroundChange.setSelection(sharedPref.getInt("VALUE", 6));
慕田峪4524236
aluckdog
相关分类