-2

Need to make a layout like this. Below is an alert box which has a transparent background containing spinner and a button below.

enter image description here

i ve tried this as far.

this is the layout file.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"

>


<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:background="#fff"
    android:paddingBottom="50dp">

<Spinner
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/selectCity_xspn"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="6dp"
    android:layout_marginTop="75dp" />

    <Spinner
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/selectCity_xspn"
        android:layout_alignParentStart="true"
        android:layout_marginTop="70dp"
        android:id="@+id/selectCtgry_xspn" />

<Button
    android:text="Button"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/button2"
    android:layout_marginTop="300dp"


    android:layout_alignParentEnd="true" />

This is the java class where i ve used the transparent option at many places but it doesnt work.

accessing the function at the bottom in the following button.

 customdialog_btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {


            onCreateDialog2().show();


        }
    });

 public Dialog onCreateDialog2() {
    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(Registeration.this);



    View dialog_view = getLayoutInflater().inflate(R.layout.custom_dialog, null);

    //dialog_view.setBackgroundResource(android.R.color.transparent);
    builder.setView(dialog_view);

    selectCity_spn=(Spinner)dialog_view.findViewById(R.id.selectCity_xspn);
    selectCtgry_spn=(Spinner)dialog_view.findViewById(R.id.selectCtgry_xspn);


    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getBaseContext(), R.array.selectCity_spn, android.R.layout.simple_spinner_dropdown_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    assert selectCity_spn != null;
    selectCity_spn.setAdapter(adapter);

    ArrayAdapter<CharSequence> adapter2 = ArrayAdapter.createFromResource(this.getBaseContext(), R.array.selectCtgry_spn, android.R.layout.simple_spinner_dropdown_item);
    adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    assert selectCtgry_spn != null;
    selectCtgry_spn.setAdapter(adapter2);

    View v = getWindow().getDecorView();
    v.setBackgroundResource(android.R.color.transparent);
    return builder.create();
}
Nilesh Singh
  • 1,750
  • 1
  • 18
  • 30
Karan Jtv
  • 25
  • 1
  • 11
  • 4
    take a look at Dialog with transparent background in Android http://stackoverflow.com/questions/10795078/dialog-with-transparent-background-in-android – Sadiq Md Asif Dec 28 '16 at 08:06

3 Answers3

1

This will do

Dialog dialog = builder.create();
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
return dialog;
Nilesh Singh
  • 1,750
  • 1
  • 18
  • 30
0

Try this:-

Dialog dialog1 = new Dialog(Main3Activity.this);

                dialog1.setCancelable(true);
                dialog1.setContentView(view1);

                dialog1.show();
Nainal
  • 1,728
  • 14
  • 27
0

you can set background transparent of any layout or any view or any component by adding this code in XML

android:background="@android:color/transparent"
lakshman kumar
  • 341
  • 4
  • 14