日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

android自定義彈出框樣式的實現方法

瀏覽:237日期:2022-09-23 18:49:41

前言:

做項目時,感覺android自帶的彈出框樣式比較丑,很多應用都是自己做的彈出框,這里也試著自己做了一個。

廢話不說先上圖片:

android自定義彈出框樣式的實現方法

實現機制

1.先自定義一個彈出框的樣式

2.自己實現CustomDialog類,繼承自Dialog,實現里面方法,在里面加載自定義樣式的彈出框;

3.使用時,與使用Dialog一樣

具體代碼

dialog_normal_layout.xml樣式文件

<?xml version='1.0' encoding='utf-8'?><FrameLayout xmlns:android='http://schemas.android.com/apk/res/android' android:layout_width='fill_parent' android:layout_height='fill_parent' android:clickable='true' android:orientation='vertical' android:padding='20.0dip' > <LinearLayout android:layout_width='fill_parent' android:layout_height='wrap_content' android:layout_gravity='center' android:background='@drawable/bg_bombbox' android:orientation='vertical' > <TextView android: android:layout_width='fill_parent' android:layout_height='40.0dip' android:gravity='center' android:text='@string/title_alert' android:visibility='visible' /> <LinearLayout android: android:layout_width='fill_parent' android:layout_height='wrap_content' android:gravity='center' ><TextViewandroid: android:layout_width='fill_parent'android:layout_height='wrap_content'android:gravity='left|center'android:lineSpacingMultiplier='1.5'android:minHeight='120.0dip'android:paddingBottom='15.0dip'android:paddingLeft='20.0dip'android:paddingRight='20.0dip'android:paddingTop='15.0dip' /> </LinearLayout> <View android:layout_width='fill_parent' android:layout_height='1.0px' android:background='#ffd0d0d0' /> <LinearLayout android:layout_width='fill_parent' android:layout_height='60.0dip' android:layout_gravity='bottom' android:background='@drawable/dialog_bottom_bg' android:gravity='center' android:orientation='horizontal' > <Buttonandroid: android:layout_width='114.0dip'android:layout_height='40.0dip'android:background='@drawable/btn_ok_selector'android:gravity='center'android:text='@string/ok' /> <Buttonandroid: android:layout_width='114.0dip'android:layout_height='40.0dip'android:layout_marginLeft='20.0dip'android:background='@drawable/btn_cancel_selector'android:gravity='center'android:text='@string/cancel' /> </LinearLayout> </LinearLayout> </FrameLayout>

其中引用的樣式文件styles.xml

<?xml version='1.0' encoding='utf-8'?><resources xmlns:android='http://schemas.android.com/apk/res/android'> <style name='AppBaseTheme' parent='android:Theme.Light'></style> <style name='AppTheme' parent='AppBaseTheme'></style> <style name='text_18_ffffff'> <item name='android:textSize'>18.0dip</item> <item name='android:textColor'>#ffffffff</item> </style> <style name='text_16_666666'> <item name='android:textSize'>16.0dip</item> <item name='android:textColor'>#ff666666</item> </style> <style name='sdw_white'> <item name='android:shadowColor'>#7fffffff</item> <item name='android:shadowDx'>0.0</item> <item name='android:shadowDy'>0.65</item> <item name='android:shadowRadius'>1.0</item> </style> <style name='sdw_79351b'> <item name='android:shadowColor'>#ff79351b</item> <item name='android:shadowDx'>0.0</item> <item name='android:shadowDy'>1.0</item> <item name='android:shadowRadius'>1.0</item> </style> <style name='text_15_ffffff_sdw' parent='@style/sdw_79351b'> <item name='android:textSize'>15.0dip</item> <item name='android:textColor'>#ffffffff</item> </style> <style name='text_15_666666_sdw' parent='@style/sdw_white'> <item name='android:textSize'>15.0dip</item> <item name='android:textColor'>#ff666666</item> </style> <style name='Dialog' parent='android:style/Theme.Dialog'> <item name='android:background'>#00000000</item> <item name='android:windowBackground'>@android:color/transparent</item> <item name='android:windowNoTitle'>true</item> <item name='android:windowIsFloating'>true</item> </style> </resources>

自定義Dialog的實現類CustomDialog

package com.dyr.custom; import android.app.Dialog;import android.content.Context;import android.content.DialogInterface;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup.LayoutParams;import android.widget.Button;import android.widget.LinearLayout;import android.widget.TextView; import com.dyr.view.R; public class CustomDialog extends Dialog { public CustomDialog(Context context) { super(context); } public CustomDialog(Context context, int theme) { super(context, theme); } public static class Builder { private Context context; private String title; private String message; private String positiveButtonText; private String negativeButtonText; private View contentView; private DialogInterface.OnClickListener positiveButtonClickListener; private DialogInterface.OnClickListener negativeButtonClickListener; public Builder(Context context) { this.context = context; } public Builder setMessage(String message) { this.message = message; return this; } /** * Set the Dialog message from resource * * @param title * @return */ public Builder setMessage(int message) { this.message = (String) context.getText(message); return this; } /** * Set the Dialog title from resource * * @param title * @return */ public Builder setTitle(int title) { this.title = (String) context.getText(title); return this; } /** * Set the Dialog title from String * * @param title * @return */ public Builder setTitle(String title) { this.title = title; return this; } public Builder setContentView(View v) { this.contentView = v; return this; } /** * Set the positive button resource and it’s listener * * @param positiveButtonText * @return */ public Builder setPositiveButton(int positiveButtonText, DialogInterface.OnClickListener listener) { this.positiveButtonText = (String) context .getText(positiveButtonText); this.positiveButtonClickListener = listener; return this; } public Builder setPositiveButton(String positiveButtonText, DialogInterface.OnClickListener listener) { this.positiveButtonText = positiveButtonText; this.positiveButtonClickListener = listener; return this; } public Builder setNegativeButton(int negativeButtonText, DialogInterface.OnClickListener listener) { this.negativeButtonText = (String) context .getText(negativeButtonText); this.negativeButtonClickListener = listener; return this; } public Builder setNegativeButton(String negativeButtonText, DialogInterface.OnClickListener listener) { this.negativeButtonText = negativeButtonText; this.negativeButtonClickListener = listener; return this; } public CustomDialog create() { LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // instantiate the dialog with the custom Theme final CustomDialog dialog = new CustomDialog(context,R.style.Dialog); View layout = inflater.inflate(R.layout.dialog_normal_layout, null); dialog.addContentView(layout, new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); // set the dialog title ((TextView) layout.findViewById(R.id.title)).setText(title); // set the confirm button if (positiveButtonText != null) { ((Button) layout.findViewById(R.id.positiveButton)) .setText(positiveButtonText); if (positiveButtonClickListener != null) { ((Button) layout.findViewById(R.id.positiveButton)) .setOnClickListener(new View.OnClickListener() { public void onClick(View v) { positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE); } }); } } else { // if no confirm button just set the visibility to GONE layout.findViewById(R.id.positiveButton).setVisibility( View.GONE); } // set the cancel button if (negativeButtonText != null) { ((Button) layout.findViewById(R.id.negativeButton)) .setText(negativeButtonText); if (negativeButtonClickListener != null) { ((Button) layout.findViewById(R.id.negativeButton)) .setOnClickListener(new View.OnClickListener() { public void onClick(View v) { negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE); } }); } } else { // if no confirm button just set the visibility to GONE layout.findViewById(R.id.negativeButton).setVisibility( View.GONE); } // set the content message if (message != null) { ((TextView) layout.findViewById(R.id.message)).setText(message); } else if (contentView != null) { // if no message set // add the contentView to the dialog body ((LinearLayout) layout.findViewById(R.id.content)) .removeAllViews(); ((LinearLayout) layout.findViewById(R.id.content)) .addView(contentView, new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT)); } dialog.setContentView(layout); return dialog; } }}

使用代碼

CustomDialog.Builder builder = new CustomDialog.Builder(this); builder.setMessage('這個就是自定義的提示框'); builder.setTitle('提示'); builder.setPositiveButton('確定', new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); //設置你的操作事項 } }); builder.setNegativeButton('取消', new android.content.DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.create().show();

至此,自定義彈出框已經完成,是不是感覺很簡單呢。

這里附上一個自定義彈出框的小項目代碼下載地址:點擊打開鏈接

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Android
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产精品第十页| 五月精品视频| 天堂va欧美ⅴa亚洲va一国产| 在线亚洲国产精品网站| 欧美中文一区二区| 久久五月天小说| 欧美a级片一区| 99在线精品视频在线观看| 日韩电影免费网址| 久久人人99| 蜜臀精品一区二区三区在线观看 | 亚洲在线免费| av不卡免费看| 亚洲涩涩av| 欧美日韩中出| 国产精品啊啊啊| 久久精品国产99国产| 国内一区二区三区| av综合电影网站| 免费视频亚洲| 丝袜美腿一区二区三区| 日韩成人av影视| 欧美黑人巨大videos精品| 成人一区而且| 亚洲韩日在线| 中文字幕成人| 欧美经典一区| 日韩精品电影一区亚洲| 国产精品地址| 色88888久久久久久影院| 欧美影院三区| 午夜在线一区| 国产欧美另类| а√天堂8资源中文在线| 欧美日韩少妇| 日本aⅴ亚洲精品中文乱码| 久久久久伊人| 91精品一区二区三区综合在线爱| 国产手机视频一区二区| 日韩国产欧美在线播放| 国产在线观看91一区二区三区| 日本免费久久| 亚洲一区二区三区中文字幕在线观看 | 日韩av一区二区在线影视| 美女国产一区二区三区| 欧美在线观看视频一区| 亚洲一级淫片| 国产不卡av一区二区| 欧美精品黄色| 国产精区一区二区| 亚洲高清不卡| 伊人精品在线| 国产日产精品_国产精品毛片| 日韩成人亚洲| 91精品在线免费视频| 欧美日韩视频免费观看| 亚洲尤物av| 黄色aa久久| 亚洲免费中文| 九九九精品视频| 精品1区2区3区4区| 九九九精品视频| 一本一道久久a久久| 中文字幕一区久| 亚洲毛片视频| 色综合www| 国产欧美日韩精品一区二区免费| 99久久亚洲精品蜜臀| 日本视频在线一区| 亚洲香蕉网站| 久久99久久人婷婷精品综合| 亚洲激情av| 色爱综合网欧美| 亚洲香蕉久久| 91精品一区二区三区综合在线爱| 欧美偷窥清纯综合图区| 国产精品97| 国产成人a视频高清在线观看| 免费人成精品欧美精品| 日韩福利一区| 欧美精品97| 奇米色欧美一区二区三区| 在线国产一区| 伊人网在线播放| 国产精品a级| 日本不卡高清| 欧美特黄一级| 激情国产在线| 美女国产一区二区三区| 亚洲无线观看| 合欧美一区二区三区| 伊人久久高清| 97se综合| 国产成人精选| 精品视频一区二区三区在线观看 | 91精品在线免费视频| 欧美特黄视频| 日韩中文视频| 中文av在线全新| 久久精品福利| 久久精品福利| 免费在线成人| 国产精品视频一区二区三区四蜜臂| 中文字幕一区二区三区日韩精品| 国产中文一区| 欧美日韩在线二区| 精品日韩视频| 亚洲播播91| 欧美成人基地| 日本美女一区| 成人影视亚洲图片在线| 精品午夜视频| 久久精品国产免费| 另类欧美日韩国产在线| 麻豆精品新av中文字幕| 国产精品xxx在线观看| 国产乱子精品一区二区在线观看| 日韩有码av| 亚洲九九精品| 日韩精品第一| 国产乱人伦精品一区| 国产精品亚洲一区二区在线观看 | 午夜av不卡| 福利一区视频| 成人在线免费观看91| 91亚洲自偷观看高清| a国产在线视频| 久久青草久久| 欧美va天堂在线| 宅男在线一区| 欧洲亚洲一区二区三区| 1024精品一区二区三区| 欧美日韩国产高清电影| 亚洲神马久久| 亚洲+小说+欧美+激情+另类| 日韩一区二区三免费高清在线观看 | 国产视频一区二| 国产麻豆一区二区三区精品视频| 欧美一区自拍| 久久中文字幕一区二区| 成人午夜在线| 欧美日韩视频网站| 免费视频一区三区| 午夜在线精品偷拍| 亚洲精品大片| 国产视频一区二区在线播放| 久久精品国产99| 久久久久久久欧美精品| 精品成人18| 欧美日韩在线二区| 美女毛片一区二区三区四区| 亚洲综合国产| 亚洲狼人精品一区二区三区| 91麻豆精品激情在线观看最新| 久久99精品久久久野外观看| 久久影院午夜精品| 日韩午夜av| 日韩av一区二区三区| 久久久免费人体| 日韩精品永久网址| 亚洲一区二区毛片| 日韩av二区在线播放| 精品不卡一区| 亚洲精品在线观看91| 婷婷综合福利| 国产欧美亚洲一区| 中文字幕在线看片| 红桃视频国产精品| 日本免费在线视频不卡一不卡二| 精品国产精品久久一区免费式| 天堂网av成人| 亚洲三级网站| 亚洲天堂资源| 视频精品一区| 国产网站在线| 色婷婷成人网| 97精品中文字幕| 亚洲欧美视频| 欧美黑人巨大videos精品| 久久蜜桃av| 国产精品一级在线观看| 91精品亚洲| 日本麻豆一区二区三区视频| 国产欧洲在线| 欧美一区免费| 欧美特黄a级高清免费大片a级| 日韩在线观看中文字幕| 麻豆成全视频免费观看在线看| 美女尤物久久精品| 日韩av二区| 日韩中文字幕一区二区高清99| 极品av在线| 亚洲精品中文字幕乱码| 精品在线网站观看| 国产免费成人| 中文字幕在线官网| 久久精品xxxxx| 麻豆理论在线观看| 日韩avvvv在线播放| 蜜桃成人av|