android美化对话框

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 {
	@Override
	protected 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() {
			
			@Override
			public 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() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO 自动生成的方法存根
				Toast.makeText(MainActivity.this, "您点击的取消", Toast.LENGTH_SHORT).show();
			}
		});
		
		alert.show();

		new Handler().postDelayed(new Runnable() {
			@Override
			public 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美化对话框_第1张图片


你可能感兴趣的:(android,对话框)