0

I am new to android , so i was playing with activity,fragments and other stuff.

This is my end goal:

enter image description here

Current scenario:

enter image description here enter image description here

Problem with this is that i have set my layout_width to match_parent so, now when the dialog comes up, it is setting itself according to wrap_content, so depending on the child sizes the dialog is getting set in width.

What i want is for the dialog to be full length; width wise.

What i tried: this answer

Basically i thought would override the theme and would add its width manually.

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:width">@dimen/dialog_width</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowAnimationStyle">@android:style/Animation</item>
    </style>

dimens.xml

<dimen name="dialog_width">@dimen/match_parent</dimen>

attribs.xml

<resources>
    <item name="match_parent" type="dimen">-1</item>
    <item name="wrap_content" type="dimen">-2</item>
</resources>

This isn't working; it's making my app crash.

My 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="wrap_content"
    android:background="#ffff"
    android:id="@+id/dialogParent1">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/dialogParent2"
        android:orientation="horizontal">
        <ImageView
            android:layout_weight="1"
            android:contentDescription="@string/contains_song_thumbnail"
            android:layout_width="0dp"
            android:layout_height="40dp"
            android:id="@+id/dialogThumnbnail"
            android:layout_margin="10dp"
            android:background="@mipmap/ic_music_note_black_24dp"
            />

        <TextView
            android:layout_weight="6"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:gravity="center"
            android:id="@+id/dialogTextview"
            android:scrollHorizontally="true"
            android:freezesText="true"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:focusableInTouchMode="true"
            />

        <ToggleButton
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text=""
            android:textOff=""
            android:layout_margin="5dp"
            android:id="@+id/dialogControl"
            android:background="@drawable/ic_play_pause_small"
            android:textOn="" />
    </LinearLayout>
    <android.support.v4.widget.Space
        android:layout_width="match_parent"
        android:layout_height="20dp" />
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="wrap_content">
        <SeekBar
            android:id="@+id/dialogSeekbar"
            android:layout_width="0dp"
            android:layout_weight="4"
            android:layout_height="wrap_content"
            />
        <TextView
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:text="@string/app_name"
            android:textSize="10sp"
            android:textStyle="bold"
            android:gravity="center"
            />
    </LinearLayout>

    <android.support.v4.widget.Space
        android:layout_width="match_parent"
        android:layout_height="20dp" />

Question is how do i make the size fix and how do i customize my dialog theme to set properly ?

P.s: this is not dialog but its an activity, i have just used the dialog theme on it.

Tilak Raj
  • 1,369
  • 5
  • 31
  • 64

1 Answers1

0

Check by replacing your XML with this,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dialogParent1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ffff"
    android:orientation="vertical"
    android:padding="10dp">

    <RelativeLayout
        android:id="@+id/dialogParent2"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/dialogThumnbnail"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@mipmap/ic_launcher"
            android:contentDescription="@string/app_name" />

        <TextView
            android:id="@+id/dialogTextview"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginHorizontal="10dp"
            android:layout_toLeftOf="@+id/dialogControl"
            android:layout_toRightOf="@+id/dialogThumnbnail"
            android:ellipsize="marquee"
            android:focusableInTouchMode="true"
            android:freezesText="true"
            android:gravity="center"
            android:marqueeRepeatLimit="marquee_forever"
            android:maxLines="2"
            android:scrollHorizontally="true" />

        <ToggleButton
            android:id="@+id/dialogControl"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_gravity="right"
            android:background="@mipmap/ic_launcher"
            android:text=""
            android:textOff=""
            android:textOn="" />
    </RelativeLayout>

    <android.support.v4.widget.Space
        android:layout_width="match_parent"
        android:layout_height="20dp" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <SeekBar
            android:id="@+id/dialogSeekbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_toLeftOf="@+id/tv1" />

        <TextView
            android:id="@+id/tv1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:text="@string/app_name"
            android:textSize="10sp"
            android:textStyle="bold" />
    </RelativeLayout>

</LinearLayout>

I think this will definitely work.

Dhruv Patel
  • 1,529
  • 1
  • 18
  • 27