Last active
May 6, 2018 11:44
-
-
Save li2/e1b6f4147e752391dcd2 to your computer and use it in GitHub Desktop.
实现 alert dialog 样式的 activity. Implement a dialog theme activity. #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
<activity android:name=".DialogThemeActivity" | |
android:theme="@style/AppTheme.DialogActivity" | |
android:excludeFromRecents="true"/> | |
<!-- 必须从「最近使用的Apps列表」中移除. Excluded from the list of recently used applications --> | |
<!-- v14/styles.xml --> | |
<style name="AppTheme.DialogActivity" parent="@android:style/Theme.Holo.Light.Dialog"/> | |
<!-- v21/styles.xml --> | |
<style name="AppTheme.DialogActivity" parent="@style/Theme.AppCompat.Light.Dialog.Alert"> | |
<item name="android:alertDialogTheme">@style/CustomAlertDialogStyle</item> | |
</style> | |
<style name="CustomAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> | |
<!-- 标题、正文的文字颜色 --> | |
<item name="android:textColorPrimary">@android:color/holo_blue_light</item> | |
<!-- window background color --> | |
<item name="android:windowBackground">@android:color/holo_purple</item> | |
<!-- SingleChoiceDialog icon color --> | |
<item name="colorAccent">@android:color/holo_green_light</item> | |
<!-- button & checkbox color --> | |
<item name="android:colorAccent">@android:color/holo_red_light</item> | |
</style> | |
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
import android.app.AlertDialog; | |
// Refer to: http://stackoverflow.com/questions/1979369/android-activity-as-a-dialog | |
public class DialogThemeActivity extends Activity { | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
new AlertDialog.Builder(this) | |
.setTitle("title") | |
.setIcon(R.drawable.ic_) | |
.setMessage("message") | |
.setCancelable(false) | |
.setPositiveButton("Ok", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
finish(); | |
} | |
}) | |
.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment