当前位置:操作系统 > 安卓/Android >>

android(九种对话框)的实现方式

 app中肯定是少不了与用户交互的各种dialog,。这里,总结了常用的9种dialog的实现方法。
   
 
 
 
除了popupwindow实现稍微麻烦一点,其他形似都相对简单,熟悉2便即可
直接上源码
 

[java]
package com.naoh.stu; 
 
import java.util.ArrayList; 
 
import android.app.Activity; 
import android.app.AlertDialog; 
import android.app.ProgressDialog; 
import android.content.DialogInte易做图ce; 
import android.graphics.drawable.BitmapDrawable; 
import android.os.Bundle; 
import android.view.Gravity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup.LayoutParams; 
import android.view.WindowManager; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.PopupWindow; 
import android.widget.Toast; 
 
public class DiaAllActivity extends Activity implements Runnable { 
    private Button btn_diaNormal;  
    private Button btn_diaMulti; 
    private Button btn_diaList; 
    private Button btn_diaSinChos; 
    private Button btn_diaMultiChos; 
    private Button btn_diaProcess; 
    private Button btn_diaReadProcess; 
    private Button btn_diaCustom; 
    private Button btn_popUpDia; 
     
    private PopupWindow window=null; 
    private Button cusPopupBtn1; 
    private View popupView; 
 
    @Override 
    public void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.dialog); 
        getView(); 
        setListener(); 
    } 
     
    private void getView() 
    { 
        btn_diaNormal=(Button)findViewById(R.id.btn_diaNormal); 
        btn_diaMulti=(Button)findViewById(R.id.btn_diaMulti); 
        btn_diaList=(Button)findViewById(R.id.btn_diaList); 
        btn_diaSinChos=(Button)findViewById(R.id.btn_diaSigChos); 
        btn_diaMultiChos=(Button)findViewById(R.id.btn_diaMultiChos); 
        btn_diaProcess=(Button)findViewById(R.id.btn_diaProcess); 
        btn_diaReadProcess=(Button)findViewById(R.id.btn_diaReadProcess); 
        btn_diaCustom=(Button)findViewById(R.id.btn_diaCustom); 
        btn_popUpDia=(Button)findViewById(R.id.btn_popUpDia); 
         
    } 
     
    private void setListener() 
    { 
        btn_diaNormal.setOnClickListener(btnListener); 
        btn_diaMulti.setOnClickListener(btnListener); 
        btn_diaList.setOnClickListener(btnListener); 
        btn_diaSinChos.setOnClickListener(btnListener); 
        btn_diaMultiChos.setOnClickListener(btnListener); 
        btn_diaProcess.setOnClickListener(btnListener); 
        btn_diaReadProcess.setOnClickListener(btnListener); 
        btn_diaCustom.setOnClickListener(btnListener); 
        btn_popUpDia.setOnClickListener(btnListener); 
    } 
     
    private Button.OnClickListener btnListener= new Button.OnClickListener() 
    { 
        public void onClick(View v) 
        { 
            if(v instanceof Button) 
            { 
                int btnId=v.getId(); 
                switch(btnId) 
                { 
                    case R.id.btn_diaNormal: 
                        showNormalDia(); 
                        break; 
                    case R.id.btn_diaMulti: 
                        showMultiDia(); 
                        break; 
                    case R.id.btn_diaList: 
                        showListDia(); 
                        break; 
                    case R.id.btn_diaSigChos: 
                        showSinChosDia(); 
                        break; 
                    case R.id.btn_diaMultiChos: 
         

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,