Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get that cross button/image on Custom dialog box's boundary?

Tags:

android

dialog

enter image description here

How to get that cross button/image (red circled) on Custom dialog box's boundary?

like image 451
Jayesh Avatar asked Dec 03 '22 09:12

Jayesh


2 Answers

Android is not Windows. You don't need a Windows style 'Close' button. Also, Android is not MacOS, so you don't need a little shiny red candy-like dot either.

When you develop an app for a mobile platform you should conform to the User Interface Guidelines that define the usage patterns and visual styles of that platform.

Android does not have title bars, does not have dropdown menus, and does not have minimize/restore/close buttons. Don't try to make them, or you will make an app that looks like it was never meant for the Android Platform.

The "Back" hardkey is the button that does exactly what you want. It closes a dialog without making a selection. Let the Android platform do the same thing here. Don't force your users to think in another OS than the one they use.

like image 68
jcwenger Avatar answered Jan 26 '23 00:01

jcwenger


HI,

you have to follow these steps to make this Custom dialog box.

  • create a xml file style.xml in your values folder. and enter style in your resource tag.

    <style name="Theme.CustomDialog"
        parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@drawable/bg_popup</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
    </style>
    
  • create a custom_dialog.xml in layout folder.

    <RelativeLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_marginRight="10dp">
        </LinearLayout>
    
        <ImageView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:background="@drawable/red_cross"
            android:layout_alignParentRight="true" android:layout_alignParentTop="true">
        </ImageView>
    </RelativeLayout>
    

  • finally access this layout in an activity it will work.

like image 45
Saurabh Pareek Avatar answered Jan 25 '23 23:01

Saurabh Pareek