I want to create a custom dialog with the layout as shown in the picture. The cross/cl
Add a button with that background and set the position alignParentTop
and alignParentRight
to true. And make the parent layout Relative
.
![anybody can try above all but u will be facing problem background color problem
i have done very simple way
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:gravity="center"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:id="@+id/left_arrow_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/up_arrow" />
<ListView
android:id="@+id/listview_observation"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="2"
android:padding="6dp" >
</ListView>
<ImageView
android:id="@+id/right_arrow_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/down_arrow" />
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#B2B2B2"
android:scrollY="@dimen/activity_vertical_margin" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="right"
android:orientation="vertical" >
<TextView
android:id="@+id/text_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:padding="6dp"
android:text="@string/Observation"
android:textSize="18sp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#B2B2B2"
android:scrollY="@dimen/activity_vertical_margin" />
<EditText
android:id="@+id/edit_observation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#00000000"
android:ems="10"
android:gravity="top" >
</EditText>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:background="#B2B2B2"
android:scrollY="@dimen/activity_vertical_margin" />
<Button
android:id="@+id/button_done"
android:layout_width="94dp"
android:layout_height="wrap_content"
android:layout_marginRight="14dp"
android:layout_marginTop="3dp"
android:background="@drawable/rectangular_view_selected"
android:text="@string/button_done"
android:textColor="@android:color/white" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="@+id/icon_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="35dp"
android:layout_marginTop="35dp"
android:src="@drawable/icon_close" />
</RelativeLayout>
the dialog must be like that
private void ChildSectionView() {
final Dialog dialog = new Dialog(NewObservationActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog_obs_children);
// Grab the window of the dialog, and change the width
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
lp.width = size.x;
lp.height = size.y;
// This makes the dialog take up the full width
window.setAttributes(lp);
gridview = (GridView) dialog.findViewById(R.id.gridview_observation);
ImageView icon_close = (ImageView) dialog.findViewById(R.id.icon_close);
child_count = (TextView) dialog
.findViewById(R.id.text_child_count_dialog);
child_count.setText("Selected " + intList.size() + " more children");
SearchView searchview = (SearchView) dialog
.findViewById(R.id.search_children);
icon_close.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
searchview.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String string) {
filItemAdapter("N", string);
return false;
}
});
filItemAdapter("", "");
dialog.show();
}
Note :-------
the relative layout background should be transparent and dialog background also dialog.getWindow().setBackgroundDrawable( new ColorDrawable(android.graphics.Color.TRANSPARENT));][2]