我的应用程序中有很多警报对话框.这是默认布局,但我在对话框中添加正负按钮.因此按钮获得Android 5(绿色)的默认文本颜色.我试图改变它但没有成功.知道如何改变文字颜色吗?
My Custom对话框:
public class MyCustomDialog extends AlertDialog.Builder {
public MyCustomDialog(Context context,String title,String message) {
super(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View viewDialog = inflater.inflate(R.layout.dialog_simple, null, false);
TextView titleTextView = (TextView)viewDialog.findViewById(R.id.title);
titleTextView.setText(title);
TextView messageTextView = (TextView)viewDialog.findViewById(R.id.message);
messageTextView.setText(message);
this.setCancelable(false);
this.setView(viewDialog);
} }
Run Code Online (Sandbox Code Playgroud)
创建对话框:
MyCustomDialog builder = new MyCustomDialog(getActivity(), "Try Again", errorMessage);
builder.setNegativeButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
...
}
}).show();
Run Code Online (Sandbox Code Playgroud)
negativeButton是一个默认的对话框按钮,采用Android 5 Lollipop的默认绿色.
非常感谢
android textcolor android-layout android-alertdialog android-5.0-lollipop
我想在Android Studio v1.0.0 rc2中将此库导入我的项目:
https://github.com/navasmdc/MaterialDesignLibrary
但有一个问题.当我将此库添加为模块时,会出现此错误:
错误:依赖项MyApplication.libraries:MaterialDesign:项目应用程序未指定解析为APK归档文件,不支持作为编译依赖项.文件:C:\ ADTBundle\StudioWorkspace\MyApplication\libraries\MaterialDesign\build\outputs\apk\MaterialDesign-release-unsigned.apk
什么是解决这个问题的分步指南?或者这个库的gradle依赖是什么?
有谁知道如何覆盖AlertDialog按钮的默认样式?我已经浏览了Android源代码中的主题和样式,并尝试了不同的东西,但我还没有找到一种有效的方法.
我下面的内容适用于更改背景,但对按钮没有任何作用.通过清单myTheme
应用于整体<application>
.(为清楚起见,删除了其他一些项目,但它们仅与标题栏相关.)
<style name="myTheme" parent="android:Theme">
<item name="android:buttonStyle">@style/customButtonStyle</item>
<item name="android:alertDialogStyle">@style/dialogAlertTheme</item>
</style>
<style name="dialogAlertTheme" parent="@android:style/Theme.Dialog.Alert">
<item name="android:fullDark">@drawable/dialog_loading_background</item>
<item name="android:topDark">@drawable/dialog_alert_top</item>
<item name="android:centerDark">@drawable/dialog_alert_center</item>
<item name="android:bottomDark">@drawable/dialog_alert_bottom</item>
<!-- this last line makes no difference to the buttons -->
<item name="android:buttonStyle">@style/customButtonStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我最近将我的应用程序迁移到了Material Design,我用我的警报对话框偶然发现了这个问题:
我正在应用这样的对话框样式:
<item name="android:alertDialogTheme">@style/Theme.AlertDialog</item>
和Theme.AlertDialog看起来像这样:
<style name="Theme.AlertDialog" parent="Base.V14.Theme.AppCompat.Dialog">
<item name="colorPrimary">@color/theme_primary</item>
<item name="colorPrimaryDark">@color/theme_primary_dark</item>
<item name="colorAccent">@color/theme_accent_dark</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这是在我的Kitkat设备上发生的,它在Lollipop上工作正常.你能帮助我摆脱那个外在的背景吗?
我的应用程序扩展Theme.AppCompat.Light
,材质样式的对话框显示为白色背景,黑色文本颜色和绿色按钮(旋转器ProgessDialog
也是绿色).
我想改变文本的颜色和字体,以及按钮和微调器的颜色.
我该怎么做?
我发现这篇文章,但XML解决方案对我不起作用,其他答案是没有的第三方库ProgressDialog
.
谢谢!
在我的应用程序中,我使用Theme.Holo和Theme.Holo.Light没有任何问题.当使用Holo主题并单击DialogPreference/ListPreference时,弹出的对话框也以Holo为主题.对于Holo.Light来说也是如此.但是,当我的自定义主题(来自Holo.Light)设置了PreferencesActivity样式时,所有对话框都以Holo.Light为主题.我想我在主题中缺少某些东西.谁能帮助我?非常感谢!
这是我的主题代码:
<?xml version="1.0" encoding="utf-8"?>
<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="GreenTheme" parent="android:Theme.Holo.Light">
<item name="android:editTextBackground">@drawable/edit_text_holo_light</item>
<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewGreenTheme</item>
<item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>
<item name="android:buttonStyle">@style/ButtonGreenTheme</item>
<item name="android:imageButtonStyle">@style/ImageButtonGreenTheme</item>
<item name="android:dropDownSpinnerStyle">@style/SpinnerGreenTheme</item>
<item name="android:tabWidgetStyle">@style/TabWidgetGreenTheme</item>
<item name="android:progressBarStyleHorizontal">@style/ProgressBarGreenTheme</item>
<item name="android:seekBarStyle">@style/SeekBarGreenTheme</item>
<item name="android:buttonStyleToggle">@style/ToggleGreenTheme</item>
<item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">@drawable/activated_background_holo_light</item>
<item name="android:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>
<item name="android:actionBarStyle">@style/ActionBar.Solid.Greenactionbar</item>
<item name="android:buttonBarButtonStyle">@style/ButtonBarButtonStyleGreenTheme</item>
<item name="android:preferenceStyle">@style/TimePickerDialogFragmentGreen</item>
</style>
<style name="TimePickerDialogFragmentGreen" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:editTextBackground">@drawable/edit_text_holo_light</item>
<item name="android:autoCompleteTextViewStyle">@style/AutoCompleteTextViewGreenTheme</item>
<item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>
<item name="android:buttonStyle">@style/ButtonGreenTheme</item>
<item name="android:imageButtonStyle">@style/ImageButtonGreenTheme</item>
<item name="android:dropDownSpinnerStyle">@style/SpinnerGreenTheme</item>
<item name="android:tabWidgetStyle">@style/TabWidgetGreenTheme</item>
<item name="android:progressBarStyleHorizontal">@style/ProgressBarGreenTheme</item>
<item name="android:seekBarStyle">@style/SeekBarGreenTheme</item>
<item name="android:buttonStyleToggle">@style/ToggleGreenTheme</item>
<item name="android:listChoiceBackgroundIndicator">@drawable/list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">@drawable/activated_background_holo_light</item>
<item …
Run Code Online (Sandbox Code Playgroud) 对于屏幕较小的特定设备,默认情况下警报消息太大,我想将其设置为自定义dp
我的警报是这样的
OnClickListener addNewItemListener = new OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(
MyActivity.this);
LinearLayout myLayout= new LinearLayout(MyActivity.this);
myLayout.setOrientation(LinearLayout.VERTICAL);
alert.setTitle(R.string.add_title);
alert.setMessage(R.string.add_message);
final TextView t1 = new TextView(MyActivity.this);
t1.setText("Name");
final EditText input1 = new EditText(MyActivity.this);
myLayout.addView(t1);
myLayout.addView(input1);
alert.setView(myLayout);
alert.setPositiveButton(R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
}
});
alert.setNegativeButton(R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
try {
....
} catch (RuntimeException e) {
Alerts.DatiErrati(MyActivity.this);
}
}
});
alert.show();
} …
Run Code Online (Sandbox Code Playgroud) 阅读MaterialComponents 主题警报对话框按钮和https://medium.com/@lcdsmao/material-design-custom-alert-dialog-5a9cab3ade11我设置AlertDialog
了新材料主题的按钮和文本颜色。
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<!-- AlertDialog -->
<item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialogTextTheme</item>
<item name="materialAlertDialogTheme">@style/MaterialAlertDialogButtonsTheme</item>
</style>
<!-- AlertDialog text -->
<style name="MaterialAlertDialogTextTheme" parent="MaterialAlertDialog.MaterialComponents.Body.Text">
<item name="android:textColor">@color/colorPrimary</item>
<item name="android:colorAccent">@color/colorPrimary</item>
<item name="colorAccent">@color/colorPrimaryitem>
<item name="android:textSize">14sp</item>
<item name="android:textStyle">bold</item>
</style>
<!-- AlertDialog buttons -->
<style name="MaterialAlertDialogButtonsTheme" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="buttonBarPositiveButtonStyle">@style/AlertDialog.Button</item>
...
Run Code Online (Sandbox Code Playgroud)
创建AlertDialogFragment
使用后
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
super.onCreateDialog(savedInstanceState)
return MaterialAlertDialogBuilder(context!!).apply {
...
}.create()
} …
Run Code Online (Sandbox Code Playgroud) android android-alertdialog material-design material-components material-components-android
我通过以下方式主题:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primaryDark</item>
<item name="colorAccent">@color/accent</item>
<item name="alertDialogTheme">@style/AppTheme.Dialog</item>
</style>
<style name="AppTheme.Dialog" parent="Theme.AppCompat.Dialog.Alert">
<item name="colorAccent">@color/accent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但是,当我在我的应用程序中创建AlertDialogs时,它们根本不是主题.其他组件如ActionBar正在正确着色.我错过了什么吗?
我使用的是AppCompat版本com.android.support:appcompat-v7:23.1.1
,我的设备安装了Android 4.4.4.