Last active
May 6, 2018 11:45
-
-
Save li2/5716e5e747973b284695 to your computer and use it in GitHub Desktop.
How to Use and Style the new AlertDialog from appCompat 22.1 and above? #tags: android-activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://stackoverflow.com/questions/29797134/how-to-use-and-style-the-new-alertdialog-from-appcompat-22-1-and-above | |
private void showViewTimeSettingDialog() { | |
// not work | |
//ContextThemeWrapper themedContext = new ContextThemeWrapper(getActivity(), R.style.CustomAlertDialogStyle); | |
//AlertDialog.Builder builder = new AlertDialog.Builder(themedContext); | |
// 向 AppTheme 中加入自定义的 AlertDialog theme 无效,必须在 Builder() 中指定 style. not work | |
/* | |
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> | |
<item name="android:alertDialogStyle">@style/CustomAlertDialogStyle</item> | |
</style> | |
//AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | |
// import android.support.v7.app.AlertDialog; | |
使用支持包,可以在 4.0 和 5.0 机器上拥有 material 风格,此时设置 holo 风格无效。 | |
<style name="CustomAlertDialogStyle" parent="android:Theme.Holo.Dialog.NoActionBar"> | |
// import android.app.AlertDialog; | |
使用,在 4.0 上是 holo 风格,在 5.0 上是 material 风格。 | |
但在 5.0 上可以更改 为 holo 风格。 | |
*/ | |
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); | |
builder.setSingleChoiceItems(R.array.string_array_dvr_video_time, 0, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
Log.d(TAG, "View Time " + which + " checked"); | |
} | |
}) | |
.setTitle(R.string.recording_item_video_time) | |
.setNegativeButton(R.string.alert_cancel, null); | |
final AlertDialog dialog = builder.create(); | |
dialog.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment