-
Notifications
You must be signed in to change notification settings - Fork 155
Adding a custom view
Javier Santos edited this page Apr 26, 2016
·
6 revisions
From the library version 1.3 you will be able to add a custom view and show whatever you want, in addition to the basic dialog. Here you are a quick guide:
<?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="match_parent">
<TextView
android:id="@+id/custom_text_view"
android:text="This is a simple demonstration on how to add custom views to the MaterialStyledDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/custom_button"
android:text="click to dismiss dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
### 2. Inflate the layout in your activity
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View customView = inflater.inflate(R.layout.custom_view, null);
TextView customText = (TextView) customView.findViewById(R.id.custom_text_view);
Button dismissButton = (Button) customView.findViewById(R.id.custom_button);
...
new MaterialStyledDialog(this)
.setDescription("What can we improve? Your feedback is always welcome.")
.setCustomView(customView)
// You can also show the custom view with some padding in DP (left, top, right, bottom)
//.setCustomView(customView, 20, 20, 20, 0)
.show();
- You can customize the dialog with other library customizations.