sách gpt4 ai đã đi

android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色

In lại 作者:太空宇宙 更新时间:2023-11-03 10:18:36 30 4
mua khóa gpt4 Nike

以前,我有一个 DialogFragment,我没有明确指定它的 UI 组件(Spinner、EditText)颜色。

dialog_fragment_layout.xml



android:layout_width="phù hợp với cha mẹ"
android:layout_height="phù hợp với cha mẹ"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:orientation="dọc" >

<>
android:id="@+id/country_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:layout_marginBottom="10dp" />


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" >





Tôi đang sử dụng

  • SherlockActionBar
  • Theme.Sherlock.Light.DarkActionBar
  • android:minSdkVersion="10", android:targetSdkVersion="21"

看起来如下

nhập mô tả hình ảnh ở đây

迁移到之后

  • 应用兼容性
  • Theme.AppCompat.Light.DarkActionBar
  • android:minSdkVersion="10", android:targetSdkVersion="22"

看起来像下面这样

nhập mô tả hình ảnh ở đây

我想知道,我在迁移过程中是否做错了什么?是否真的需要明确地为 DialogFragment UI 组件(Spinner、EditText)颜色指定特定颜色?

有没有办法让 DialogFragment 看起来不错,而无需像我们所做的那样手动为 Spinner、EditText 等分配颜色(我们让系统决定最佳颜色当我们使用 SherlockActionBar 时用于 Spinner、EditText、...)?

请注意,我没有在 Activity hoặc DialogFragment 中指定特定主题。我只在 Application 中指定主题,并且我希望我的 Activity hoặc DialogFragment 将继承自 Application.

<ứng>
android:theme="@style/..." >

DialogFragment 的代码是

DialogFragment 源代码

public class MyDialogFragment extends android.support.v4.app.DialogFragment {

public static MyDialogFragment newInstance() {
return new MyDialogFragment();
}

@Ghi đè
Hộp thoại công khai onCreateDialog(Gói 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() {
@Ghi đè
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.tạo nên();

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() {

@Ghi đè
public void onShow(DialogInterface dialogInterface) {

Button b = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {

@Ghi đè
public void onClick(View view) {
...
}
});
}
});

return dialog;
}

显示DialogFragment的代码

private void showMyDialogFragment() {        
FragmentManager fm = this.getActivity().getSupportFragmentManager();
MyDialogFragment myDialogFragment = MyDialogFragment.newInstance();
myDialogFragment.setTargetFragment(this, 0);
myDialogFragment.show(fm, MY_DIALOG_FRAGMENT);
}

1 Câu trả lời

AlertDialog 的支持库版本,support.v7.app.AlertDialog , 添加于 Android Support Library 22.1 ,为所有 API7+ 设备带来单一 Material 样式对话框(以及其中的 View 主题)。如果您使用的是 AppCompat,则还应该使用支持库 AlertDialog.

关于android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30181172/

30 4 0
太空宇宙
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com