亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

android中定制的dialog

系統 2201 0

?

    public ShelfSwitchDialog(Context context) {
		super(context,android.R.style.Theme_NoTitleBar);
		setContentView(R.layout.newspaper_switch_dialog);
		this.context = context;
		Window win = getWindow();
		win.getAttributes().gravity = Gravity.TOP;
		win.setBackgroundDrawableResource(R.drawable.newspaper_blank);
		//大小
		win.setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	}
  

? ? dialog的定制 :

? ? public class ShelfSwitchDialog extends Dialog implements OnClickListener{

    	Context context;
	ImageView yingyong,shudian,baojia;
	int selectIndex;
	String[] choiceItems = new String[]{"圖書","報架"};
	
	public ShelfSwitchDialog(Context context,int paddingLeft){
		this(context);
		View v = findViewById(R.id.dialog_root_layout);
		v.setPadding(paddingLeft-50,50,v.getPaddingRight(),v.getPaddingBottom());
		yingyong = (ImageView)findViewById(R.id.yingyong);
		yingyong.setOnClickListener(this);
		shudian = (ImageView)findViewById(R.id.shudian);
		shudian.setOnClickListener(this);
		baojia = (ImageView)findViewById(R.id.baojia);
		baojia.setOnClickListener(this);
	}
	
	public ShelfSwitchDialog(Context context) {
		super(context,android.R.style.Theme_NoTitleBar);
		setContentView(R.layout.newspaper_switch_dialog);
		this.context = context;
		Window win = getWindow();
		win.getAttributes().gravity = Gravity.TOP;
		win.setBackgroundDrawableResource(R.drawable.newspaper_blank);
		//大小
		win.setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	}
	public AlertDialog create(){
		if(context==null){return null;}
		final boolean instOfStore = context instanceof ShelfActivity||context instanceof BooksListActivity;
		final boolean instOfShelf = context instanceof NewspaperShelf;
		final Intent shelfIntent = new Intent(context,NewspaperShelf.class);
		final Intent storeIntent = new Intent(context,ShelfActivity.class);
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		AlertDialog dialog =  builder
        .setIcon(R.drawable.newspaper_ic_switch)
        .setTitle("切換到:")
        .setSingleChoiceItems(choiceItems, 0, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            	selectIndex =  whichButton;
            }
        })
        .setPositiveButton("確定", new DialogInterface.OnClickListener() {
        	
            public void onClick(DialogInterface dialog, int whichButton) {
//            	Log.v("","whichButton:"+selectIndex);
            	if(instOfStore){
            		switch(selectIndex){
            		case 0:
            			Toast.makeText(context,"當前已是書店",Toast.LENGTH_SHORT).show();
            			break;
            		case 1:
            			context.startActivity(shelfIntent);
            			break;
            		}
            	}
            	else if(instOfShelf){
            		switch(selectIndex){
            		case 0:
            			((ShelfActivity)context).finish();
            			break;
            		case 1:
            			Toast.makeText(context,"當前已是報架",Toast.LENGTH_SHORT).show();
            			break;
            		}
            	}
            }
        })
        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            	
            }
        })
       .create();
		dialog.getWindow().getAttributes().gravity = Gravity.TOP;
		dialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
		return dialog;
	}

	@Override
	public void onClick(View v) {
		final boolean instOfShelf = context instanceof ShelfActivity;
		final boolean instOfNewspaperShelf = context instanceof NewspaperShelf;
		final boolean instOfStoreActivity = context instanceof StoreActivity;
		final boolean instOfBooksListActivity = context instanceof BooksListActivity;
		final Intent newspaperShelfIntent = new Intent(context,NewspaperShelf.class);
		final Intent shelfIntent = new Intent(context,ShelfActivity.class);
		switch(v.getId()){
		case R.id.yingyong:
			Intent intent = new Intent("cn.chutong.ereader.finishactivity");
			dismiss();
			context.sendBroadcast(intent);
			break;
		case R.id.shudian:
			if(instOfNewspaperShelf){
				((NewspaperShelf)context).finish();
				dismiss();
			}
			else if(instOfShelf||instOfBooksListActivity){
				Toast.makeText(context,"當前已是書店",Toast.LENGTH_SHORT).show();
				dismiss();
			}
			else if(instOfStoreActivity){
				dismiss();
				((StoreActivity)context).finish();
				context.startActivity(shelfIntent);
			}
			break;
		case R.id.baojia:
			if(instOfNewspaperShelf){
				Toast.makeText(context,"當前已是報架",Toast.LENGTH_SHORT).show();
				dismiss();
			}
			else if(instOfShelf||instOfBooksListActivity){
				context.startActivity(newspaperShelfIntent);
				dismiss();
			}
			else if(instOfStoreActivity){
				context.startActivity(newspaperShelfIntent);
				dismiss();
				((StoreActivity)context).finish();
			}
			break;
		
		}
	}
}
  
?

? ?效果圖:

?

?


android中定制的dialog

?

?

第二種情況:

?

    addCustomDlg = new Dialog(this, R.style.dialog);
addCustomDlg.setContentView(R.layout.add);
addCustomDlg.show();
confirmBtn = (Button) addCustomDlg.findViewById(R.id.confirmBtn);
edit = (EditText) addCustomDlg.findViewById(R.id.txt);
edit.setText("");
btn_back = (ImageButton) addCustomDlg.findViewById(R.id.btn_back);
btn_back.setOnClickListener(this);
confirmBtn.setOnClickListener(this);
  

? ?直接從dialog中獲取控件,并綁定事件

? 效果:


android中定制的dialog

android中定制的dialog


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 日韩精品中文字幕视频一区 | 亚洲欧美综合精品成 | 久久天天躁狠狠躁夜夜 | 国产成人亚洲毛片 | 一级特黄特色aa大片 | 亚洲精品乱码久久久久久中文字幕 | 欧美成人h精品网站 | 天海翼一区二区在线观看 | 中文字幕 国产精品 | 国产精品永久免费视频观看 | 交专区videossex另类 | 99999久久久久久亚洲 | 五月国产综合视频在线观看 | 天天擦天天干 | 欧美国产成人精品一区二区三区 | 日本在线 | 中文 | 亚洲国产精品综合久久 | 精品九九久久 | 青青青视频自偷自拍视频1 青青青手机版视频在线观看 | 欧美成人免费大片888 | 成人黄色免费 | 91国自产精品中文字幕亚洲 | 久久亚洲精品成人 | 女人18一级毛片免费观看 | 四虎免费在线观看视频 | 一区二区三区四区视频在线观看 | avtt亚洲一区中文字幕 | 97视频在线免费 | 国产精品视频麻豆 | 精品国产欧美一区二区 | 性做久久久久久蜜桃花 | 特黄级| 成 人 黄 色 大 片全部 | 久久久久久久综合色一本 | 免费久久精品视频 | 久久国产精品广西柳州门 | 日本中文字幕在线观看视频 | 国产精品亚洲综合色区韩国 | 亚色视频在线观看 | 日韩午夜网站 | 欧美精品18xxxhd4k |