日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

android中定制的dialog

系統(tǒng) 2350 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,"當(dāng)前已是書店",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,"當(dāng)前已是報架",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,"當(dāng)前已是書店",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,"當(dāng)前已是報架",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


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

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

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 利津县| 合阳县| 无棣县| 利辛县| 武清区| 达日县| 四川省| 平罗县| 鹤庆县| 庆元县| 邯郸县| 法库县| 伽师县| 肥东县| 富源县| 会昌县| 日喀则市| 安义县| 镇沅| 菏泽市| 新田县| 台江县| 凉山| 泽州县| 阜新市| 石门县| 和平县| 子长县| 德江县| 彭州市| 雷山县| 江永县| 长垣县| 旌德县| 延寿县| 凤翔县| 沁阳市| 尼勒克县| 神农架林区| 阿城市| 陇西县|