android美化对话框
16lz
2021-12-04
package com.example.dialog_1;import android.app.Activity;import android.app.AlertDialog;import android.content.DialogInterface;import android.os.Bundle;import android.os.Handler;import android.view.ContextThemeWrapper;import android.widget.Toast;public class MainActivity extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// ///弹出是否添加城市的 对话框ContextThemeWrapper contextThemeWrapper =new ContextThemeWrapper(MainActivity.this, R.style.dialog);final AlertDialog alert = new AlertDialog.Builder(contextThemeWrapper).create();alert.setTitle("悟空提示");alert.setMessage("您是第8位用户");alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new android.content.DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO 自动生成的方法存根Toast.makeText(MainActivity.this, "您点击的确定", Toast.LENGTH_SHORT).show();}});alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new android.content.DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog, int which) {// TODO 自动生成的方法存根Toast.makeText(MainActivity.this, "您点击的取消", Toast.LENGTH_SHORT).show();}});alert.show();new Handler().postDelayed(new Runnable() {@Overridepublic void run() {///alert.dismiss();}}, 2000);}// //onCreate}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="${relativePackage}.${activityClass}" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /></RelativeLayout>
styles.xml
<resources> <!-- Base application theme, dependent on API level. This theme is replaced by AppBaseTheme from res/values-vXX/styles.xml on newer devices. --> <style name="AppBaseTheme" parent="android:Theme.Light"> <!-- Theme customizations available in newer API levels can go in res/values-vXX/styles.xml, while customizations related to backward-compatibility can go here. --> </style> <!-- Application theme. --> <style name="AppTheme" parent="AppBaseTheme"> <!-- All customizations that are NOT specific to a particular API-level can go here. --> </style> <style name="dialog" parent="@android:style/Theme.Dialog"> <item name="android:textSize">20sp</item> </style></resources>比原生的美观很多,但是后面字体并没有变大,在改变 <item name="android:textSize">20sp</item>时。
更多相关文章
- android 对话框大全
- Android(安卓)菜单栏菜单功能
- android 对话框大全
- Android(安卓)弹出对话框Dialog
- android图像变为黑白
- Android之警告对话框alertdialog
- android两种方法操作Sqlite数据库
- Android震动---启动、循环、取消控制
- Android(安卓)Dialog对话框的七种形式的使用