0

I have this custom layout because I want a ListView with TextView below it and I want to handle click on list items so dialog doesn't close. (AlertDialog will show its own message view above its ListView.)

<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>

I made a fake setup where I put text in both the dialog's TextView and my layout's. Screenshot of the result.

Heading

I even tried putting style="?android:attr/textAppearanceMedium" in @id/messageView in my layout since alert_dialog.xml has it. It made the text larger than the dialog's message. And the color doesn't match, too light (as if it's the Activity's default color).

I even tried using the builder's LayoutInflater, which is what the documentation says to do.

                val infl = builder.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
                val view = infl.inflate(R.layout.dialog_report_profile, null)
                builder.setView(view)
androidguy
  • 3,005
  • 2
  • 27
  • 38

1 Answers1

0

You can always put both style="?android:attr/textAppearanceMedium" AND android:color="#000" at your TextView.

Or, you can just add this to your res/styles.xml:

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

and put this line to your TextView: style="@style/DialogMessageText"

shiftpsh
  • 1,926
  • 17
  • 24
  • OK, but as I said, it seems like Medium makes it larger. Not sure why. Do you have any other advice for matching the text size with the Dialog views? – androidguy May 22 '17 at 00:51
  • You can use `@android:style/TextAppearance.DeviceDefault.DialogWin‌​dowTitle` instead. – shiftpsh May 22 '17 at 11:11