Translucent screen android

Someone tell me how to design a dialog or activity like this in the picture in android.I searched the web but couldn't get the corresponding result.

enter image description here

Please, help

Thankyou.

+3


source to share


2 answers


Personally, I use android Dialog

, but I use a custom layout that matches my app's design.

Here's an example:

new AlertDialog.Builder(context)
.setView(inflater.inflate(R.layout.dialog_delete_contact, null))
.setPositiveButton(context.getResources().getString(android.R.string.ok).toUpperCase(), new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {
        // YOUR TREATMENT
    }
})
.setNegativeButton(context.getResources().getString(android.R.string.cancel).toUpperCase(), null)
.show();

      

Markup:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/GrayLight"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@color/Black"
    android:gravity="center"
    android:orientation="horizontal"
    tools:ignore="DisableBaselineAlignment" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_weight="2"
        android:gravity="center"
        android:orientation="horizontal" >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/app_name"
            android:fitsSystemWindows="true"
            android:padding="10dip"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:layout_marginRight="20dp"
        android:layout_weight="0.5"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/remove_contact"
            android:textColor="@color/White"
            android:textSize="20sp"
            android:textStyle="bold"
            tools:ignore="HardcodedText" />

    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:gravity="center"
    android:orientation="vertical"
    tools:ignore="DisableBaselineAlignment" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingBottom="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:paddingTop="20dp"
        android:text="@string/ask_remove_contact"
        android:textSize="15sp"
        tools:ignore="HardcodedText" />

</LinearLayout>

      



Result in the picture:

enter image description here

To avoid rewriting code every time, this is the utility class:

public class MyDialog {

public static Builder create(final Context context, final LayoutInflater layoutInflater, final String title, final String content) {
    View view = layoutInflater.inflate(R.layout.generic_dialog, null);
    ((TextView)view.findViewById(R.id.textViewTitleDialog)).setText(title);
    ((TextView)view.findViewById(R.id.textViewContentDialog)).setText(content);
    return new AlertDialog.Builder(context).setView(view);
}

}

      

And an example of use:

AlertDialog.Builder myDialog = MyDialog.create(this, getLayoutInflater(), "Quitter ECOLEMS", "Voulez-vous vraiment quitter l'application?");
myDialog.setPositiveButton("Oui", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {
        // YOUR TREATMENT
    }
})
.setNegativeButton("Non", null)
.show();

      

+5


source


You can create Activity

and set a theme

 <?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="Theme.Transparent" parent="android:Theme">
    <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:backgroundDimEnabled">false</item>
  </style>
</resources>

      



set theme as

<activity android:name=".yourActivity" android:theme="@style/Theme.Transparent"/>

      

+2


source







All Articles