zoukankan      html  css  js  c++  java
  • android基类Dialog

    import android.app.Dialog;
    import android.content.Context;
    import android.os.Bundle;
    import android.util.DisplayMetrics;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.WindowManager;
    import android.widget.BaseAdapter;
    
    import com.xh.boke.R;
    
    /**
     * 自定义基类Dialog
     * Created by Administrator on 2015/10/21 0021.
     */
    public class BaseDialog extends Dialog {
    
        protected Context mContext;
        protected BaseAdapter mAdapter;
        protected View convertView;
        protected int resId;    //view
        protected double percent; //屏幕宽度百分比
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            init();
        }
    
        public BaseDialog(Context context, int resId,double percent) {
            super(context, R.style.common_custom_dialog);
            this.mContext=context;
            this.resId =resId;
            this.percent = percent;
        }
    
        public BaseDialog(Context context, int resId,BaseAdapter adapter,double percent) {
            super(context, R.style.common_custom_dialog);
            this.mContext=context;
            this.mAdapter = adapter;
            this.resId =resId;
            this.percent = percent;
        }
    
        protected void init() {
            //设置布局
            convertView = LayoutInflater.from(mContext).inflate(resId, null);
            this.setContentView(convertView);
    
            // 获取屏幕的宽高
            WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
            DisplayMetrics dm = new DisplayMetrics();
            wm.getDefaultDisplay().getMetrics(dm);
    
            WindowManager.LayoutParams p = getWindow().getAttributes(); // 获取对话框当前的参数值
            p.width = (int) (dm.widthPixels * percent); // 宽度设置为屏幕的百分比
            this.getWindow().setAttributes(p);
        }
    }

    styles.xml

    <resources>
    
        <!-- dialog默认样式 -->
        <style name="common_custom_dialog" parent="android:style/Theme.Dialog">
            <item name="android:windowFrame">@null</item>
            <item name="android:windowIsFloating">true</item>
            <item name="android:windowIsTranslucent">true</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:background">@android:color/transparent</item>
            <item name="android:windowBackground">@android:color/transparent</item>
            <item name="android:backgroundDimEnabled">true</item>
            <item name="android:backgroundDimAmount">0.6</item>
        </style>
    
    </resources>
  • 相关阅读:
    R语言统计词频 画词云
    Bootstrap抽样(自展法)
    基于adt-bundle-windows-x86的android开发环境搭建
    逆分布函数法生成随机数(指数分布) R语言实现
    2016-ccf-data-mining-competition 搜狗用户画像构建
    算法第四版 在Linux 中调用Algs4库
    解决Ubuntu Chrome浏览器很卡不响应的问题
    Linux下安装系统清理软件 BleachBit 1.4
    C语言编程-9_4 字符统计
    C++调用Matlab函数求特征值
  • 原文地址:https://www.cnblogs.com/kangweifeng/p/4898093.html
Copyright © 2011-2022 走看看