0

我有這個自定義佈局,因爲我想要一個ListView與TextView 下面它,我想處理單擊列表項,所以對話框不關閉。 (AlertDialog將展示其上面的ListView它自己的消息視圖)。我該如何讓TextView裏面的自定義佈局中的TextView添加到AlertDialog中以匹配Dialog的?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:app="http://schemas.android.com/apk/res-auto" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:paddingStart="14dp" 
       android:paddingEnd="10dp" 
    > 
    <ListView 
     android:id="@+id/optionList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:overScrollMode="never" 
     android:choiceMode="singleChoice" 
     android:divider="@null" 
     /> 
    <TextView 
     android:id="@+id/messageView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:padding="5dp" 
     /> 
</LinearLayout> 

我做了一個假的設置,其中我把文本對話框的TextView的,我的佈局的兩個。結果屏幕截圖。

Heading

我甚至試圖把style="?android:attr/textAppearanceMedium"在@ ID /在消息查看我的佈局,因爲alert_dialog.xml有它。它使文本大於對話框的消息。顏色不匹配,太亮(就像它是Activity的默認顏色一樣)。

我甚至嘗試過使用構建器的LayoutInflater,這是文檔所說的。

   val infl = builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater 
       val view = infl.inflate(R.layout.dialog_report_profile, null) 
       builder.setView(view) 

回答

0

您可以隨時在兩者的TextViewstyle="?android:attr/textAppearanceMedium"android:color="#000"放。

或者,你可以添加到您的RES/styles.xml:

<style name="DialogMessageText" parent="@android:style/TextAppearance.Medium"> 
    <item name="android:textColor">@android:color/black</item> 
</style> 

,並把此行到您的TextView:style="@style/DialogMessageText"

+0

好的,但正如我所說,它看起來像中等使它更大。不知道爲什麼。您是否有任何其他建議將文本大小與Dialog視圖匹配? – user3175580

+0

您可以改用'@android:style/TextAppearance.DeviceDefault.DialogWin dowTitle'。 – shiftpsh

相關問題