0

I have been working on a ListView that allows me to display individual custom list objects, as well as group objects which contain the aforementioned individual list objects. At first I started by using an ExpandableListView, but I didn't like the way that it looked. Instead, I decided to use a Dialog with a custom layout in order to display the children of a group object within my ListView, as shown below:

enter image description here

Here is the layout for my Dialog:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/helmet_listview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="5dp"
        android:cacheColorHint="@android:color/transparent"
        android:choiceMode="multipleChoice"
        android:layout_weight="1"
        android:isScrollContainer="false">
    </ListView>

    <LinearLayout
        android:id="@+id/btnHolderLL"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/dismiss_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:paddingRight="1dp"
            android:paddingLeft="1dp"
            android:textColor="#FFFFFF"
            android:background="@drawable/button_selector"
            android:text="Dismiss"
            android:clickable="true" />

    </LinearLayout>

</LinearLayout>

They layout is basically just a copy of the layout used for the main Activity that contains the Listview, but while said Activity contains the action bar, the Dialog does not. So my question is, how do I go about adding a simple action bar with a title, as shown in the main Activity, to my Dialog. As a side note, I also noticed that the ListView in my Dialog doesn't have any dividers. This is not as important as the action bar, but some insight into this would be appreciated as well.

Willis
  • 5,308
  • 3
  • 32
  • 61
  • possible duplicate of [ActionBar in a DialogFragment](http://stackoverflow.com/questions/11425020/actionbar-in-a-dialogfragment) – Simas Jan 14 '15 at 18:15
  • The above example is not a `DialogFragment`, it is a simple `Dialog`.. – Willis Jan 14 '15 at 18:22
  • I don't have any issues with using a `Fragment` and if that is the only solution then I can implement the above `Dialog` as a `Fragment`. Using a `Dialog` was simply a matter of convenience – Willis Jan 14 '15 at 18:29
  • You could also fairly easily put a [Toolbar](http://developer.android.com/reference/android/widget/Toolbar.html) in your Dialog's layout. If your app's minSdk is below Lollipop, you can also use it from AppCompat v21. Toolbar seems to be the "new ActionBar", so it might be a good thing to check out anyway. – Jonba Jan 14 '15 at 18:44

1 Answers1

1

Wrap all with a relativelayout and insert another relativelayout as the actionbar with alignment top. You can align your main layout below the actionbar. If you want the shadow effect of material design, add elevation 8dp to the actionbar-like layout.

Mann
  • 661
  • 5
  • 9