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

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Android修改Dialog樣式的方法

瀏覽:112日期:2022-09-18 14:43:56
目錄一、Dialog源碼解析1.1 new AlertDialog.Builder(this).create()1.2 AlertController二、修改Dialog樣式2.1 通過(guò)findViewById2.2 自定義style一、Dialog源碼解析1.1 new AlertDialog.Builder(this).create()

protected AlertDialog(@NonNull Context context, @StyleRes int themeResId) {super(context, resolveDialogTheme(context, themeResId));//創(chuàng)建AlertController,是Dialog布局相關(guān)代碼mAlert = new AlertController(getContext(), this, getWindow()); }@NonNullpublic AlertDialog create() { // We can’t use Dialog’s 3-arg constructor with the createThemeContextWrapper param, // so we always have to re-set the theme final AlertDialog dialog = new AlertDialog(P.mContext, mTheme); P.apply(dialog.mAlert); dialog.setCancelable(P.mCancelable); if (P.mCancelable) {dialog.setCanceledOnTouchOutside(true); } dialog.setOnCancelListener(P.mOnCancelListener); dialog.setOnDismissListener(P.mOnDismissListener); if (P.mOnKeyListener != null) {dialog.setOnKeyListener(P.mOnKeyListener); } return dialog;}public void apply(AlertController dialog) { if (mCustomTitleView != null) {dialog.setCustomTitle(mCustomTitleView); } else {if (mTitle != null) { dialog.setTitle(mTitle);}if (mIcon != null) { dialog.setIcon(mIcon);}if (mIconId != 0) { dialog.setIcon(mIconId);} .......... AlertDialog 構(gòu)造函數(shù)中會(huì)創(chuàng)建 AlertController,用來(lái)控制對(duì)話(huà)框的布局 P.apply(dialog.mAlert); 將用戶(hù)自定義的配置賦值給 AlertController 1.2 AlertController

public AlertController(Context context, AppCompatDialog di, Window window) {mContext = context;mDialog = di;mWindow = window;mHandler = new ButtonHandler(di);final TypedArray a = context.obtainStyledAttributes(null, R.styleable.AlertDialog,R.attr.alertDialogStyle, 0);mAlertDialogLayout = a.getResourceId(R.styleable.AlertDialog_android_layout, 0);mButtonPanelSideLayout = a.getResourceId(R.styleable.AlertDialog_buttonPanelSideLayout, 0);mListLayout = a.getResourceId(R.styleable.AlertDialog_listLayout, 0);mMultiChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_multiChoiceItemLayout, 0);mSingleChoiceItemLayout = a.getResourceId(R.styleable.AlertDialog_singleChoiceItemLayout, 0);mListItemLayout = a.getResourceId(R.styleable.AlertDialog_listItemLayout, 0);mShowTitle = a.getBoolean(R.styleable.AlertDialog_showTitle, true);mButtonIconDimen = a.getDimensionPixelSize(R.styleable.AlertDialog_buttonIconDimen, 0);a.recycle();/* We use a custom title so never request a window title */di.supportRequestWindowFeature(Window.FEATURE_NO_TITLE); }

R.attr.alertDialogStyle 是 對(duì)話(huà)框的默認(rèn)樣式,

<item name='alertDialogStyle'>@style/AlertDialog.AppCompat</item><style name='AlertDialog.AppCompat' parent='Base.AlertDialog.AppCompat'/> <style name='Base.AlertDialog.AppCompat' parent='android:Widget'><item name='android:layout'>@layout/abc_alert_dialog_material</item><item name='listLayout'>@layout/abc_select_dialog_material</item><item name='listItemLayout'>@layout/select_dialog_item_material</item><item name='multiChoiceItemLayout'>@layout/select_dialog_multichoice_material</item><item name='singleChoiceItemLayout'>@layout/select_dialog_singlechoice_material</item><item name='buttonIconDimen'>@dimen/abc_alert_dialog_button_dimen</item> </style>

上述代碼可以看出,abc_alert_dialog_material 就是dialog的默認(rèn)布局。

<androidx.appcompat.widget.AlertDialogLayout xmlns:android='http://schemas.android.com/apk/res/android' android: android:layout_width='match_parent' android:layout_height='wrap_content' android:gravity='start|left|top' android:orientation='vertical'> <include layout='@layout/abc_alert_dialog_title_material'/> <FrameLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:minHeight='48dp'><View android: android:layout_width='match_parent' android:layout_height='1dp' android:layout_gravity='top' android:background='?attr/colorControlHighlight' android:visibility='gone'/><androidx.core.widget.NestedScrollView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:clipToPadding='false'> <LinearLayoutandroid:layout_width='match_parent'android:layout_height='wrap_content'android:orientation='vertical'><android.widget.Space android: android:layout_width='match_parent' android:layout_height='@dimen/abc_dialog_padding_top_material' android:visibility='gone'/><TextView android: android:layout_width='match_parent' android:layout_height='wrap_content' android:paddingLeft='?attr/dialogPreferredPadding' android:paddingRight='?attr/dialogPreferredPadding'/><android.widget.Space android: android:layout_width='match_parent' android:layout_height='@dimen/abc_dialog_padding_top_material' android:visibility='gone'/> </LinearLayout></androidx.core.widget.NestedScrollView><View android: android:layout_width='match_parent' android:layout_height='1dp' android:layout_gravity='bottom' android:background='?attr/colorControlHighlight' android:visibility='gone'/> </FrameLayout> <FrameLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:minHeight='48dp'><FrameLayout android: android:layout_width='match_parent' android:layout_height='wrap_content'/> </FrameLayout> <include layout='@layout/abc_alert_dialog_button_bar_material' android:layout_width='match_parent' android:layout_height='wrap_content'/></androidx.appcompat.widget.AlertDialogLayout>

標(biāo)題布局:

<!-- abc_alert_dialog_title_material: --><LinearLayout xmlns:android='http://schemas.android.com/apk/res/android' android: android:layout_width='match_parent' android:layout_height='wrap_content' android:orientation='vertical'> <!-- If the client uses a customTitle, it will be added here. --> <LinearLayoutandroid: android:layout_width='match_parent'android:layout_height='wrap_content'android:gravity='center_vertical|start|left'android:orientation='horizontal'android:paddingLeft='?attr/dialogPreferredPadding'android:paddingRight='?attr/dialogPreferredPadding'android:paddingTop='@dimen/abc_dialog_padding_top_material'><ImageView android: android:layout_width='32dip' android:layout_height='32dip' android:layout_marginEnd='8dip' android:layout_marginRight='8dip' android:scaleType='fitCenter' android:src='http://www.b3g6.com/bcjs/@null'/><androidx.appcompat.widget.DialogTitle android: android:layout_width='match_parent' android:layout_height='wrap_content' android:layout_gravity='start' android:ellipsize='end' android:singleLine='true' android:textAlignment='viewStart'/> </LinearLayout> <android.widget.Spaceandroid: android:layout_width='match_parent'android:layout_height='@dimen/abc_dialog_title_divider_material'android:visibility='gone'/></LinearLayout>

按鈕布局:

<!-- abc_alert_dialog_button_bar_material: --><ScrollView xmlns:android='http://schemas.android.com/apk/res/android' android: android:layout_width='match_parent' android:layout_height='wrap_content' android:fillViewport='true' android:scrollIndicators='top|bottom'> <androidx.appcompat.widget.ButtonBarLayoutandroid:layout_width='match_parent'android:layout_height='wrap_content'android:gravity='bottom'android:layoutDirection='locale'android:orientation='horizontal'android:paddingBottom='4dp'android:paddingLeft='12dp'android:paddingRight='12dp'android:paddingTop='4dp'><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content'/><android.widget.Space android: android:layout_width='0dp' android:layout_height='0dp' android:layout_weight='1' android:visibility='invisible'/><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content'/><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content'/> </androidx.appcompat.widget.ButtonBarLayout></ScrollView>二、修改Dialog樣式2.1 通過(guò)findViewById

AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(msg); builder.setPositiveButton(getString(R.string.yes), null); AlertDialog dialog = builder.create(); dialog.show(); //直接通過(guò)id找到對(duì)應(yīng)的控件 Button button = dialog.findViewById(android.R.id.button1); //或者通過(guò)getButton方法也可以獲取到 Button button2 = dialog.getButton(DialogInterface.BUTTON_POSITIVE);

這種修改方式必須在 show() 之后調(diào)用,否則會(huì)出現(xiàn)空指針異常。這個(gè)是因?yàn)椋瑘?zhí)行 show() 方法的時(shí)候,dialog才會(huì)初始化布局,具體源碼可以查看 Dialog 的 onCreate 方法。

2.2 自定義style

通過(guò)上面源碼可以發(fā)現(xiàn),Dialog三個(gè)按鈕的樣式如下:

buttonBarNeutralButtonStyle buttonBarNegativeButtonStyle buttonBarPositiveButtonStyle

<Button android: android:layout_width='wrap_content' android:layout_height='wrap_content'/><android.widget.Space android: android:layout_width='0dp' android:layout_height='0dp' android:layout_weight='1' android:visibility='invisible'/><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content'/><Button android: android:layout_width='wrap_content' android:layout_height='wrap_content'/>

自定義樣式替換上述 style即可達(dá)到修改效果。

在style.xml添加如下代碼:

<style name='accessPositiveBtnStyle' parent='Widget.AppCompat.Button.ButtonBar.AlertDialog'><item name='android:textColor'>@color/test1</item> </style> <style name='accessNegativeBtnStyle' parent='Widget.AppCompat.Button.ButtonBar.AlertDialog'><item name='android:textColor'>@color/test2</item> </style> <!-- 彈出框樣式 --> <style name='testDialogTheme' parent='Theme.AppCompat.Light.Dialog.Alert'><item name='buttonBarPositiveButtonStyle'>@style/accessPositiveBtnStyle</item><item name='buttonBarNegativeButtonStyle'>@style/accessNegativeBtnStyle</item> </style>

具體使用:

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.testDialogTheme); builder.setMessage('Test'); builder.setCancelable(false); builder.setPositiveButton('確認(rèn)', null); builder.setNegativeButton('取消', null); Dialog dialog = builder.create(); dialog.show();

以上就是Android修改Dialog樣式的方法的詳細(xì)內(nèi)容,更多關(guān)于A(yíng)ndroid修改Dialog樣式的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Android
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
欧美三级精品| 久久精品影视| 久久三级视频| 欧美日韩一二三四| 久久中文字幕二区| 91精品观看| 麻豆精品91| 日韩不卡一区二区| 日本成人在线视频网站| 88久久精品| 国产aa精品| 私拍精品福利视频在线一区| 午夜久久免费观看| 亚洲免费在线| 午夜久久av | 久久亚洲影院| 日韩激情啪啪| 福利一区二区免费视频| 欧美成人日韩| 日韩精品五月天| 国产一区丝袜| 麻豆精品91| 日本一二区不卡| 亚洲一区日韩在线| 7777精品| 亚洲网站视频| 91精品一区| 亚洲二区免费| 青青伊人久久| 免费成人网www| 国产乱码精品一区二区三区四区 | 国产精品久久久久久久久久久久久久久| 欧美精品成人| 九九久久电影| 久久精品免费看| 午夜一级在线看亚洲| 欧美国产日韩电影| 蜜臀av性久久久久蜜臀aⅴ流畅| 色狠狠一区二区三区| 欧美日韩在线观看视频小说| 国产日本久久| 中文字幕亚洲在线观看| 久久久国产精品一区二区中文| 日本综合视频| 日韩中文字幕亚洲一区二区va在线 | 日韩1区2区日韩1区2区| 国产一区亚洲| 九九色在线视频| 久久亚州av| 综合一区在线| 在线亚洲观看| 国产韩日影视精品| 香蕉成人av| 天堂av在线| 91视频一区| 国产精品15p| 日韩精品免费视频一区二区三区| 欧美日韩色图| 美女网站视频一区| 粉嫩av一区二区三区四区五区| 日韩不卡在线观看日韩不卡视频| 亚洲不卡av不卡一区二区| 日本精品黄色| 国产成人精品亚洲线观看| 日韩精品导航| 石原莉奈在线亚洲三区| 欧美日韩国产高清电影| 亚洲天堂资源| 天堂中文av在线资源库| 国产不卡一区| 亚洲啊v在线| 日韩欧美精品| 久久中文字幕av| 欧美女激情福利| 久久国产精品久久久久久电车| 免费观看在线综合色| 国产精品最新| 精品国产第一福利网站| 最新日韩欧美| 国产日韩高清一区二区三区在线| 男人的天堂亚洲一区| 国产无遮挡裸体免费久久| 国产一区丝袜| 亚洲免费一区二区| 国产精品xxx| 亚洲国产专区校园欧美| 日韩午夜视频在线| 久久久久久网| 蜜桃久久av一区| 国产精品红桃| 久久久久久久久99精品大| 午夜亚洲一区| 麻豆mv在线观看| 亚洲一区二区三区在线免费| 青草av.久久免费一区| 精品视频免费| 免播放器亚洲一区| 国产在线观看www| 色8久久久久| 免费看久久久| 久久国产福利| 日韩精品专区| 国产精品一区二区三区www| 超级白嫩亚洲国产第一| 日韩精品免费视频人成 | 蜜桃av一区二区三区电影| 日韩一区电影| 精品91久久久久| 欧美偷窥清纯综合图区| 欧美日韩色图| 亚洲精品国产嫩草在线观看 | 人人爱人人干婷婷丁香亚洲| 亚洲在线成人| 欧美激情另类| 欧美影院精品| 精品在线91| 国产精品日韩精品在线播放 | 巨乳诱惑日韩免费av| 九九九精品视频| 久久高清免费观看| 欧美日韩国产亚洲一区| 高清久久精品| 国产精品白丝一区二区三区| 婷婷亚洲成人| 国产二区精品| 国产中文在线播放| 成人台湾亚洲精品一区二区| 日韩国产一区| 国产视频网站一区二区三区| 日韩专区在线视频| 不卡视频在线| 中文一区一区三区免费在线观| 免费欧美日韩| 蜜桃一区二区三区| 亚洲a一区二区三区| 蜜桃成人av| 免费在线观看日韩欧美| 日韩区一区二| 日韩精品一区二区三区中文| 蜜臀91精品一区二区三区| 亚洲黄页一区| 日韩激情中文字幕| 国产精品v日韩精品v欧美精品网站| 国产精品极品国产中出| av高清不卡| 日韩中文在线电影| 激情欧美一区| 日本精品一区二区三区在线观看视频| 亚洲在线电影| 国产激情精品一区二区三区| 日韩欧美一区免费| 一区二区国产在线| 精品视频黄色| 在线亚洲观看| 精品视频在线你懂得| 在线中文字幕播放| 六月丁香综合| 四虎国产精品免费观看| 在线日韩成人| 999精品一区| 日韩欧美中文字幕在线视频| 黄色aa久久| 国产欧美日韩影院| 99久久婷婷这里只有精品| 日本va欧美va精品发布| 香蕉成人av| 美腿丝袜在线亚洲一区| 欧美另类综合| 在线人成日本视频| 国产精品一区二区av交换| 美女被久久久| 99精品视频在线观看免费播放| 国产精品毛片久久久| 水野朝阳av一区二区三区| 亚洲精品在线影院| 久久女人天堂| 日本成人在线网站| 亚洲一区二区三区四区电影| 亚洲免费福利| 麻豆精品在线观看| 亚洲精品四区| 日韩精品一区第一页| 一区二区亚洲精品| 日本欧美不卡| 日韩免费视频| 国产乱码午夜在线视频| 国产一区二区三区久久| 麻豆极品一区二区三区| 国产精品任我爽爆在线播放| 一区二区三区国产在线| 日韩中文av| 日本午夜精品久久久| 日韩国产一区二| 日韩一区二区三免费高清在线观看| 亚洲精品午夜av福利久久蜜桃| 日韩欧美综合| 激情欧美日韩一区| 久久av一区| 97久久精品| 麻豆久久一区|