我想增加警告对话框消息文本的文本大小,所以我添加了以下样式:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/MainActionBar</item>
<item name="android:textAppearance">@android:style/TextAppearance</item>
<item name="android:textAppearanceLarge">@android:style/TextAppearance.Large</item>
<item name="android:alertDialogStyle">@style/AlertDialog</item>
</style>
<style name="TextAppearance" parent="@android:style/TextAppearance">
<item name="android:textSize">24sp</item>
</style>
<style name="TextAppearance.Large">
<item name="android:textSize">28sp</item>
</style>
<style name="AlertDialog" parent="@android:style/Theme.Holo.Light.Dialog">
<item name="android:textAppearanceMedium">@style/TextAppearance.Large</item>
</style>
</resources>
但是,在显示对话框时不会应用样式。
我错过了什么?
答案 0 :(得分:1)
主题
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:background">@android:color/white</item>
<item name="android:textColor">#000000</item>
</style>
AlertDialog
private void prompt() {
AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(
getActivity(), R.style.AppCompatAlertDialogStyle));
alert.setTitle("Update SSID");
alert.setMessage(Html.fromHtml("<font color='#009688'>Do you want to update Heater SSID </font><font color='red'><u>" + Constants.WIFI_SSID.toUpperCase() + "</u></font><font color='#009688'> ?</font>"));
LinearLayout layout = new LinearLayout(getActivity());
layout.setOrientation(LinearLayout.VERTICAL);
final TextView secure = new TextView(getActivity());
secure.setTypeface(Util.setCustomFont(getActivity()));
final EditText titleBox = new EditText(getActivity());
titleBox.setTypeface(Util.setCustomFont(getActivity()));
secure.setText(Html.fromHtml("<font color='#009688'><br><b>Enter new SSID</b></font>"));
/*Edittext setting*/
titleBox.setGravity(View.TEXT_ALIGNMENT_GRAVITY);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(35, 5, 35, 10);
titleBox.setLayoutParams(params);
titleBox.setSingleLine(true);
titleBox.setBackgroundResource(R.drawable.edit_text);
titleBox.setTextColor(Color.parseColor("#505050"));
titleBox.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
// titleBox.setText("****************");
titleBox.setTextSize(12);
/*Textview setting*/
LinearLayout.LayoutParams paramss = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
paramss.setMargins(35, 10, 35, 5);
secure.setLayoutParams(paramss);
layout.addView(secure);
layout.addView(titleBox);
alert.setView(layout);
alert.setPositiveButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).setNegativeButton("UPDATE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
});
final AlertDialog alertDialog = alert.create();
alertDialog.show();
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(false);
titleBox.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
int ssidLength = charSequence.length();
if (ssidLength == 0) {
return;
}
if (!Character.isLetterOrDigit(charSequence.charAt(ssidLength - 1))) {
titleBox.getText().delete(ssidLength - 1, ssidLength);
return;
}
if (ssidLength < 2) {
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(false);
} else {
alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setEnabled(true);
}
if (ssidLength > 12) {
titleBox.getText().delete(ssidLength - 1, ssidLength);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
}
edit_text.xml
<?xml version="1.0" encoding="utf-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:thickness="0dp">
<stroke
android:width="0.5dp"
android:color="#009688" />
<gradient
android:angle="270"
android:endColor="#ffffff"
android:startColor="#ffffff"
android:type="linear" />
</shape>
答案 1 :(得分:0)
尝试将父母添加到&#34; TextAppearance.Large&#34;风格。
<style name="TextAppearance.Large" parent="@android:style/TextAppearance">
<item name="android:textSize">28sp</item>
</style>