Android自定义圆角dialog

MyDialog.java:

package com.weijie.app_user.activity.login;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class MyDialog extends Dialog {
    
    private static int default_width = 160; //默认宽度
    private static int default_height = 120;//默认高度
    
    public MyDialog(Context context, View layout, int style) {
        this(context, default_width, default_height, layout, style);
    }
    
    public MyDialog(Context context, int width, int height, View layout, int style) {
        super(context, style);
        setContentView(layout);
        Window window = getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.width=width;
        params.height=height;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);
    }
    
}

 

 

cztest_main.xml:

 




	

 

 

 

 

 

CzTestActivity.java:

 

package com.weijie.app_user.activity.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.PopupWindow;

import com.weijie.app_user.R;
import com.weijie.app_user.activity.login.MyDialog;

public class CzTestActivity extends Activity {

	private Button mybut = null; // 定义按钮
	private PopupWindow popWin = null; // 弹出窗口
	private View popView = null; // 保存弹出窗口布局

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		super.setContentView(R.layout.cztest_main); // 调用布局管理器
		this.mybut = (Button) super.findViewById(R.id.mybut); // 取得按钮
		this.mybut.setOnClickListener(new OnClickListenerImpl()); // 设置事件类
	}

	// 新版本
	private class OnClickListenerImpl implements OnClickListener {

		@Override
		public void onClick(View view) {
			View view1 = getLayoutInflater().inflate(R.layout.login_newversion_dialog,
					null);
			MyDialog myDialog = new MyDialog(CzTestActivity.this, 300, 200, view1,
					R.style.self_dialog);
			// 设置对话框显示的View
			myDialog.show();
		}
	}

	// 选择社交平台弹出窗
	/*
	 * private class OnClickListenerImpl implements OnClickListener {
	 * 
	 * @Override public void onClick(View view) { LayoutInflater inflater =
	 * LayoutInflater.from(CzTestActivity.this); // 取得LayoutInflater对象
	 * CzTestActivity.this.popView = inflater.inflate(
	 * R.layout.login_social_platform_dialog, null); // 读取布局管理器
	 * CzTestActivity.this.popWin = new PopupWindow(popView,
	 * LayoutParams.MATCH_PARENT, 380, true); // 实例化PopupWindow //
	 * 设置PopupWindow的弹出和消失效果
	 * 
	 * CzTestActivity.this.popWin .setAnimationStyle(R.style.popupAnimation);
	 * 
	 * CzTestActivity.this.popWin.showAtLocation( CzTestActivity.this.mybut,
	 * Gravity.BOTTOM, 0, 0); // 显示弹出窗口 } }
	 */

}

 

 

 

 

 

login_newversion_dialog.xml:

 




    

        
    

    

        
    

    

    

        

        

        
    

    

    

        

        
    

 

 

 

 

 

rounded_corners_view.xml:

 



	
	
	
	
	
	
	

 

 

 

 

 

round_corner_view_title.xml:

 




    

    

    

    

 

 

 

 

 

 

Android自定义圆角dialog_第1张图片

你可能感兴趣的:(Android进阶)