Android 在使用AppCompat时,是否需要明确指定其UI组件(微调器、编辑文本)的颜色
以前,我有一个Android 在使用AppCompat时,是否需要明确指定其UI组件(微调器、编辑文本)的颜色,android,android-layout,android-appcompat,Android,Android Layout,Android Appcompat,以前,我有一个对话框片段,我没有明确指定其UI组件(微调器、编辑文本)的颜色 对话框\u fragment\u layout.xml 对话框片段的代码为 DialogFragment的源代码 显示对话框片段的代码 中添加的AlertDialog的支持库版本为所有API7+设备带来了一个单一的材质样式对话框(以及其中视图的主题化)。如果您使用的是AppCompat,您还应该使用支持库AlertDialogthemetheme.Sherlock.Light技术上是Holo系列Holo.Light的兼
对话框片段
,我没有明确指定其UI组件(微调器、编辑文本)的颜色
对话框\u fragment\u layout.xml
对话框片段的代码为
DialogFragment的源代码
显示对话框片段的代码
中添加的AlertDialog的支持库版本为所有API7+设备带来了一个单一的材质样式对话框(以及其中视图的主题化)。如果您使用的是AppCompat,您还应该使用支持库AlertDialog
themetheme.Sherlock.Light
技术上是Holo系列Holo.Light的兼容版本。在appcompat库中,themetheme.appcompat.Light
是材质族的兼容版本。因此,上述行为是意料之中的,因为Spinner和EditText等小部件都采用了新的材质设计
如果要保留Holo外观,则必须从values-v21
开始指定自己的样式,稍后在v14和v11中继承。这篇文章展示了如何为spinner实现这一点:您是否使用了support.v7版本的AlertDialog?那么您实际创建对话框的代码在哪里?@ianhanniballake我更新了这个问题。这是创建和显示对话框片段的一种非常标准的方法。不,我说的是onCreateDialog()
中实际创建对话框的代码-您只包含了构建视图的代码,而不是对话框本身。@ianhanniballake OK。我明白你的意思。编辑。如果您需要进一步的澄清,请告诉我。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="vertical" >
<Spinner
android:id="@+id/country_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:layout_marginBottom="10dp" />
<EditText
android:id="@+id/name_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions|textCapWords"
android:maxLength="50"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
<application
android:theme="@style/..." >
public class MyDialogFragment extends android.support.v4.app.DialogFragment {
public static MyDialogFragment newInstance() {
return new MyDialogFragment();
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.dialog_fragment_layout, null);
final Spinner countrySpinner = (Spinner)view.findViewById(R.id.country_spinner);
final EditText nameEditText = (EditText)view.findViewById(R.id.name_edit_text);
final CountryArrayAdapter countryArrayAdapter = new CountryArrayAdapter(this.getActivity());
countrySpinner.setAdapter(countryArrayAdapter);
nameEditText.setHint(R.string.new_watchlist_hint);
nameEditText.setText(org.yccheok.jstock.watchlist.Utils.getDefaultWatchlistName());
Utils.placeCursorAtEndOfText(nameEditText);
final AlertDialog dialog = new AlertDialog.Builder(this.getActivity())
.setTitle(R.string.new_watchlist_title)
.setView(view)
// Add action buttons
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.create();
dialog.setCanceledOnTouchOutside(true);
// http://stackoverflow.com/questions/2620444/how-to-prevent-a-dialog-from-closing-when-a-button-is-clicked
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
...
}
});
}
});
return dialog;
}
private void showMyDialogFragment() {
FragmentManager fm = this.getActivity().getSupportFragmentManager();
MyDialogFragment myDialogFragment = MyDialogFragment.newInstance();
myDialogFragment.setTargetFragment(this, 0);
myDialogFragment.show(fm, MY_DIALOG_FRAGMENT);
}