第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

帶有 RecyclerView 的自定義對(duì)話框不顯示“確定”取消按鈕

帶有 RecyclerView 的自定義對(duì)話框不顯示“確定”取消按鈕

慕桂英546537 2023-09-13 10:19:42
我有一個(gè)簡(jiǎn)單的自定義多選項(xiàng)目對(duì)話框。如果項(xiàng)目數(shù)量很少,則對(duì)話框可以正常工作并在底部顯示“確定”和“取消”按鈕。但如果有很多項(xiàng)目(因此您必須滾動(dòng)列表)-則不會(huì)顯示任何按鈕。我已經(jīng)在 SO 中搜索了我的問(wèn)題,但沒(méi)有運(yùn)氣。我已經(jīng)在 Android API 27..29 上測(cè)試了我的對(duì)話框 - 是一樣的。也許我在布局屬性等中遺漏了一些重要的東西......布局/select_exercises_dialog.xml:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical" android:layout_width="match_parent"    android:layout_height="match_parent">    <androidx.recyclerview.widget.RecyclerView        android:id="@+id/recyclerView"        android:layout_width="match_parent"        android:layout_height="match_parent" /></LinearLayout>布局/select_exercise_item_view.xml:<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    android:layout_width="match_parent"    android:layout_height="@dimen/list_item_height"    android:layout_marginLeft="@dimen/margin_medium"    android:layout_marginRight="@dimen/margin_medium"    android:gravity="center_vertical">    <androidx.constraintlayout.widget.ConstraintLayout        android:layout_width="match_parent"        android:layout_height="match_parent">        <TextView            android:id="@+id/textView"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_margin="@dimen/margin_medium"            android:text="MyExercise"            app:layout_constraintBottom_toBottomOf="parent"            app:layout_constraintStart_toStartOf="parent"            app:layout_constraintTop_toTopOf="parent" />    </androidx.constraintlayout.widget.ConstraintLayout></FrameLayout>如何解決此問(wèn)題并使對(duì)話框在所有情況下都顯示“確定”、“取消”按鈕?任何幫助表示贊賞。
查看完整描述

3 回答

?
守著星空守著你

TA貢獻(xiàn)1799條經(jīng)驗(yàn) 獲得超8個(gè)贊

如果您正在使用對(duì)話框片段,它是對(duì)話框風(fēng)格的片段,具有一些對(duì)話框規(guī)范,現(xiàn)在如果您想添加“確定”和“取消”,您有兩種選擇


從 AlertDialog.Builder 擴(kuò)展類,并在創(chuàng)建時(shí)添加正負(fù)按鈕處理程序和文本

關(guān)于代碼的示例將如下所示


class ExampleDialog(context: Context) : AlertDialog.Builder(context) {



private val view by lazy {

    LayoutInflater.from(context).inflate(R.layout.dialog_exmaple, null, false)

}


override fun setView(layoutResId: Int): AlertDialog.Builder {


    // do the recylceview init from the view code here 


    return super.setView(view)

}



override fun setPositiveButton(

    text: CharSequence?,

    listener: DialogInterface.OnClickListener?

): AlertDialog.Builder {

    return super.setPositiveButton(

        context.getText(R.string.action_ok)

    ) { p0, p1 ->



    }

}



override fun setNegativeButton(

    text: CharSequence?,

    listener: DialogInterface.OnClickListener?

): AlertDialog.Builder {

    return super.setNegativeButton(

        context.getText(R.string.action_cancel)

    ) { p0, p1 ->



    }

}

}


注意我不喜歡這種分配方式


您可以在 xml 內(nèi)添加兩個(gè)按鈕到回收視圖的底部,然后向它們添加文本,例如“確定”和“取消”,并通過(guò)高階函數(shù)或界面處理 onClick,這取決于您,我可以向您展示和示例以下

我更喜歡這段代碼對(duì)我來(lái)說(shuō)更干凈,并在dialogFragment類中添加點(diǎn)擊偵聽器


<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:layout_width="match_parent"

android:layout_height="match_parent">



<androidx.recyclerview.widget.RecyclerView

    android:id="@+id/listData"

    android:layout_width="0dp"

    android:layout_height="0dp"

    app:layout_constraintBottom_toTopOf="@id/actionOk"

    app:layout_constraintEnd_toEndOf="parent"

    app:layout_constraintStart_toStartOf="parent"

    app:layout_constraintTop_toTopOf="parent" />



<com.google.android.material.button.MaterialButton

    android:id="@+id/actionOk"

    style="@style/Widget.MaterialComponents.Button.OutlinedButton"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_margin="16dp"

    android:text="@string/action_ok"

    app:layout_constraintBottom_toBottomOf="parent"

    app:layout_constraintEnd_toEndOf="parent"

    app:layout_constraintTop_toBottomOf="@id/listData" />


<com.google.android.material.button.MaterialButton

    android:id="@+id/actionCancel"

    style="@style/Widget.MaterialComponents.Button.OutlinedButton"

    android:layout_width="wrap_content"

    android:layout_height="wrap_content"

    android:layout_margin="16dp"

    android:text="@string/action_cancel"

    app:layout_constraintBottom_toBottomOf="parent"

    app:layout_constraintEnd_toStartOf="@id/actionOk"

    app:layout_constraintTop_toBottomOf="@id/listData" />

  override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

    val dialog = super.onCreateDialog(savedInstanceState)

    val root = ConstraintLayout(activity)

    root.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)

    dialog.setContentView(root)

    dialog.window?.let {

        it.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

        it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

        it.setWindowAnimations(R.style.DialogAnimationNormal)

    }

    dialog.setCanceledOnTouchOutside(true)

    return dialog

}


查看完整回答
反對(duì) 回復(fù) 2023-09-13
?
波斯汪

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超4個(gè)贊

根據(jù)建議的解決方案即興創(chuàng)作并得出了這個(gè)(仍然不完全是我需要的):


<?xml version="1.0" encoding="utf-8"?>

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

? ? xmlns:app="http://schemas.android.com/apk/res-auto"

? ? android:id="@+id/linearLayout3"

? ? android:layout_width="match_parent"

? ? android:layout_height="match_parent"

? ? android:minHeight="150dp">


? ? <androidx.recyclerview.widget.RecyclerView

? ? ? ? android:id="@+id/recyclerView"

? ? ? ? android:layout_width="0dp"

? ? ? ? android:layout_height="0dp"

? ? ? ? app:layout_constraintBottom_toBottomOf="parent"

? ? ? ? app:layout_constraintEnd_toEndOf="parent"

? ? ? ? app:layout_constraintStart_toStartOf="parent"

? ? ? ? app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

此布局至少顯示“確定”、“取消”按鈕和包含項(xiàng)目的列表。但在這種情況下,我的對(duì)話框仍然不想占用設(shè)備屏幕的所有可用空間。列表recyclerView非常有限(高度只有150dp左右)。當(dāng)然,我希望對(duì)話框占據(jù)盡可能多的可用空間。

https://img1.sycdn.imooc.com/65011c9f0001ce2304910870.jpg

查看完整回答
反對(duì) 回復(fù) 2023-09-13
?
蝴蝶刀刀

TA貢獻(xiàn)1801條經(jīng)驗(yàn) 獲得超8個(gè)贊

   <?xml version="1.0" encoding="utf-8"?>

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

        android:orientation="vertical" android:layout_width="match_parent"

        android:layout_height="match_parent"

android:minHeight= "200dp">



        <androidx.recyclerview.widget.RecyclerView

            android:id="@+id/recyclerView"

            android:layout_width="match_parent"

            android:layout_height="wrap_content" />

    </LinearLayout>


    <?xml version="1.0" encoding="utf-8"?>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"

        xmlns:app="http://schemas.android.com/apk/res-auto"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginLeft="@dimen/margin_medium"

        android:layout_marginRight="@dimen/margin_medium"

        android:gravity="center_vertical">


        <androidx.constraintlayout.widget.ConstraintLayout

            android:layout_width="match_parent"

            android:layout_height="match_parent">


            <TextView

                android:id="@+id/textView"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                android:layout_margin="@dimen/margin_medium"

                android:text="MyExercise"

                app:layout_constraintBottom_toBottomOf="parent"

                app:layout_constraintStart_toStartOf="parent"

                app:layout_constraintTop_toTopOf="parent" />


            <CheckBox

                android:id="@+id/checkBox"

                android:layout_width="wrap_content"

                android:layout_height="wrap_content"

                app:layout_constraintBottom_toBottomOf="parent"

                app:layout_constraintEnd_toEndOf="parent"

                app:layout_constraintTop_toTopOf="parent" />


        </androidx.constraintlayout.widget.ConstraintLayout>


    </FrameLayout>


查看完整回答
反對(duì) 回復(fù) 2023-09-13
  • 3 回答
  • 0 關(guān)注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)