zoukankan      html  css  js  c++  java
  • Android基础篇自定义Dialog(二)

    很多情况下,我们需要自定义一些Dialog效果。

    首先继承系统的Dialog

    /**
     * @author gongchaobin
     *
     * 自定义Dialog样式
     */
    public class SelfDialog extends Dialog implements android.view.View.OnClickListener{
        private Context mContext;
        private Button mBtnCha;
        private Button mBtnUse;
        private ActivityManagerCommon managerCommon;
        
        public SelfDialog(Context context) {
            super(context);
            // TODO Auto-generated constructor stub
            mContext = context;
        }
    
        public SelfDialog(Context context, boolean cancelable,
                OnCancelListener cancelListener) {
            super(context, cancelable, cancelListener);
            // TODO Auto-generated constructor stub
        }
    
        public SelfDialog(Context context, int theme) {
            super(context, theme);
            // TODO Auto-generated constructor stub
            mContext = context;
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.dialog);
            
            managerCommon = ActivityManagerCommon.getScreenManager();
            mBtnCha = (Button) findViewById(R.id.dialog_cha_close);
            mBtnUse = (Button) findViewById(R.id.dialog_use);
            
            mBtnCha.setOnClickListener(this);
            mBtnUse.setOnClickListener(this);
        }
    
        public void onClick(View v) {
            // TODO Auto-generated method stub
            switch (v.getId()) {
            case R.id.dialog_cha_close:
                dismiss();
                break;
            case R.id.dialog_use://跳转到指引界面
                dismiss();
                Intent intent = new Intent(mContext,GuideActivity.class);
                mContext.startActivity(intent);
                break;
            default:
                break;
            }
        }
        
    }

    dialog.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="496dp"
        android:layout_height="334dp"
        android:background="@drawable/lst_about_bg"
        android:orientation="vertical" >
        
        <Button 
            android:layout_marginLeft="424dp"
            android:layout_marginTop="20dp"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/cha_bg_selector"
            android:id="@+id/dialog_cha_close"/>
        
        <Button 
            android:layout_width="162dp"
            android:layout_height="46dp"
            android:id="@+id/dialog_use"
            android:background="@drawable/use_bg_selector"
            android:layout_marginLeft="166dp"
            android:layout_marginTop="106dp"
            />
        
    </LinearLayout>

    同时定义Dialog的一个显示style:

        <style name="MyDialog" parent="@android:Theme.Dialog">
            <item name="android:windowFrame">@null</item>
            <item name="android:windowNoTitle">true</item> 
            <item name="android:windowBackground">@drawable/lst_about_bg</item>
            <item name="android:windowIsFloating">true</item>
            <item name="android:windowContentOverlay">@null</item>
        </style>
  • 相关阅读:
    thinkphp3.2升级至thinkphp5.0.24
    matlab从曲线图提取数据
    Pandorabox(Openwrt) 双宽带(WAN) 叠加网络实战
    大数据挖掘复习小记
    j2ee课程设计—基于activiti的请休假系统
    算法与数据结构第八次作业——散列表
    算法与数据结构——AVL树(平衡二叉树)
    算法与数据结构第六、七次作业——树
    算法与数据结构第六次作业——排序
    算法与数据结构——排序
  • 原文地址:https://www.cnblogs.com/gongcb/p/2534729.html
Copyright © 2011-2022 走看看