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

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條評論
主站蜘蛛池模板: 日本久久久久中文字幕 | 完整日本特级毛片 | 黄色成人免费观看 | 在线亚洲欧美 | 免费伊人| 亚洲欧美日韩国产一区二区精品 | 伊人网狠狠干 | 不卡无毒免费毛片视频观看 | 国产精品亚洲欧美日韩久久 | 高清一级毛片一本到免费观看 | 日韩高清在线日韩大片观看网址 | 欧美刺激午夜性久久久久久久 | 欧美成人三级视频 | 久久综合九色综合欧美狠狠 | 在线综合+亚洲+欧美中文字幕 | 久久久综合中文字幕久久 | 插插插色综合 | 久久久久欧美精品观看 | 精品国产综合区久久久久99 | 99热精品久久| 久久亚洲精品视频 | 亚洲 欧美 bt | 国产性色视频 | 久久99热成人精品国产 | 日韩在线a视频免费播放 | 免费99 | 免费视频网站在线观看黄 | 中文字幕天天躁夜夜狠狠综合 | 欧美操穴视频 | 激情影院a | 天天搞天天搞 | 国产精品一区二区综合 | 中文字幕在线视频观看 | 亚洲国产精品一区二区久久 | 中文字幕一区二区三区在线观看 | 亚洲第一区香蕉_国产a | 欧美一级片在线免费观看 | 日韩精品一区二区三区高清 | 成人久久网 | 99久热成人精品视频 | 午夜毛片福利 |