對話框(dialog)的種種

不做概念性介紹 只寫例子和遇到的問題

例子1

解決的問題是
1 MaterialDialog設(shè)置自定義布局的時(shí)候 設(shè)置title和按鈕時(shí)沒有效果的,因?yàn)樽远x布局覆蓋了MaterialDialog 的布局肘交,所以只能自己在自定義布局中將 title 和 兩個(gè)按鈕 畫出來 然后設(shè)置值和事件監(jiān)聽
2 editText在dialog中無法輸入的問題
            MaterialDialog dialog = new MaterialAlertDialog(this);
                               //設(shè)置自定義布局
            dialog.setContentView(R.layout.view_group_chat_details_group_name_dialog);
             View customView = dialog.getCustomView();
                       //我在自定義布局中放了個(gè)editText
            MinMaxEditText editText = customView.findViewById(R.id.group_name_change_et);
            DinTextView saveButton = customView.findViewById(R.id.group_name_save);
            saveButton.setOnClickListener(v -> {
                model.handleGroupNameChange(editText.getText());
                dialog.dismiss();
            });
            DinTextView cancelButton = customView.findViewById(R.id.group_name_cancel);
            cancelButton.setOnClickListener(v -> dialog.dismiss());

            //設(shè)置dialog 顯示的時(shí)候 調(diào)起鍵盤  miss的時(shí)候  隱藏鍵盤
            dialog.setOnShowListener(dialogInterface -> KeypadUtils.showSoftKeyboard(editText));
            dialog.setOnCancelListener(dialogInterface -> KeypadUtils.hideSoftKeyboard(editText));
            // 這句代碼解決了  editText 在dialog中的時(shí)候 無法輸入的問題
            dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
            dialog.show();
布局如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <com.grindrapp.android.view.DinTextView
        android:id="@+id/group_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:textColor="@color/grindr_pure_black"
        android:text="@string/chat_group_details_group_name"
        android:textStyle="bold"
        android:layout_alignParentTop="true"
        android:layout_marginTop="25dp"
        android:layout_marginLeft="27dp"
        android:layout_alignParentLeft="true"/>

    <com.grindrapp.android.view.MinMaxEditText
        android:id="@+id/group_name_change_et"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:layout_below="@id/group_name"
        android:layout_alignLeft="@+id/group_name"
        android:layout_marginRight="29dp"
        app:charLimit="30"
        app:minMaxEditTextColor="@color/grindr_grey_5"/>

    <com.grindrapp.android.view.DinTextView
        android:id="@+id/group_name_cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="@color/grindr_grey_3"
        android:textSize="16sp"
        android:text="@string/cancel"
        android:layout_alignBottom="@+id/group_name_save"
        android:layout_toLeftOf="@+id/group_name_save"
        android:layout_marginRight="28dp"/>

    <com.grindrapp.android.view.DinTextView
        android:id="@+id/group_name_save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:textColor="@color/grindr_goldenrod"
        android:text="@string/ok"
        android:layout_marginTop="33dp"
        android:layout_marginBottom="29dp"
        android:layout_marginRight="29dp"
        android:layout_below="@+id/group_name_change_et"
        android:layout_alignParentRight="true"/>
</RelativeLayout>
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市墩邀,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌宫盔,老刑警劉巖融虽,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異灼芭,居然都是意外死亡有额,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進(jìn)店門彼绷,熙熙樓的掌柜王于貴愁眉苦臉地迎上來巍佑,“玉大人,你說我怎么就攤上這事寄悯∮┧ィ” “怎么了?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵热某,是天一觀的道長腻菇。 經(jīng)常有香客問我,道長昔馋,這世上最難降的妖魔是什么筹吐? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮秘遏,結(jié)果婚禮上丘薛,老公的妹妹穿的比我還像新娘。我一直安慰自己邦危,他們只是感情好洋侨,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著倦蚪,像睡著了一般希坚。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上陵且,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天裁僧,我揣著相機(jī)與錄音,去河邊找鬼慕购。 笑死聊疲,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的沪悲。 我是一名探鬼主播获洲,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼殿如!你這毒婦竟也來了贡珊?” 一聲冷哼從身側(cè)響起最爬,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎飞崖,沒想到半個(gè)月后烂叔,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡固歪,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年蒜鸡,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片牢裳。...
    茶點(diǎn)故事閱讀 39,902評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡逢防,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出蒲讯,到底是詐尸還是另有隱情忘朝,我是刑警寧澤,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布判帮,位于F島的核電站局嘁,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏晦墙。R本人自食惡果不足惜悦昵,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望晌畅。 院中可真熱鬧但指,春花似錦、人聲如沸抗楔。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽连躏。三九已至剩岳,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間入热,已是汗流浹背卢肃。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留才顿,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓尤蒿,卻偏偏與公主長得像郑气,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個(gè)殘疾皇子腰池,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容