Reputation: 4840
I noticed something very useful in Google apps.
When we have dialog with big content, divider line is showing in order to emphasize ability to scroll, like in this two pictures:
But, I have no idea how to implement such behaviour using known utils.
Best example is while choosing phone ring, at the start there is only divider on the bottom, but when we start scrolling two dividers appear.
QUESTION
How to implement appearing and disappearing behaviour in dialog?
Upvotes: 3
Views: 4773
Reputation: 906
If you have custom layout like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scroll_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:id="@+id/views_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
you can inflate View and find ScrollView by
v.findViewById(R.id.scroll_container)
and set scroll TOP and BOTTOM indicators if you have TITLE above and BUTTONS below your custom view
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final int indicators = View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM;
scrollView.setScrollIndicators(indicators, View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM);
}
Upvotes: 1
Reputation: 22173
Looking at Android source code the solution is really simple. Just add this code to your custom view:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
final int indicators = (hasTopPanel() ? View.SCROLL_INDICATOR_TOP : 0)
| (hasBottomPanel() ? View.SCROLL_INDICATOR_BOTTOM : 0);
view.setScrollIndicators(indicators, View.SCROLL_INDICATOR_TOP | View.SCROLL_INDICATOR_BOTTOM);
}
Upvotes: 0
Reputation: 941
The behaviour that you want to achieve comes with a Dialog with Scrollable Content
. Please read this document to get an idea of that.
In this case, you need to create your own custom layout xml with ListView
and couple of buttons. And you need to keep this entire layout under ScrollView
.
The following is just a dummy code to help you with:
Edited the dummy code with the actual one::
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ListView"/>
</LinearLayout>
MainActivity.class:
LayoutInflater inflater= LayoutInflater.from(this);
view=inflater.inflate(R.layout.layout, null);
ListView listView = (ListView)view.findViewById(R.id.ListView);
String[] items = { "Milk", "Butter", "Yogurt", "Toothpaste", "Ice Cream" };
ArrayAdapter adapter_dest = new ArrayAdapter(this,android.R.layout.simple_list_item_1,items);
listView.setAdapter(adapter_dest);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Custom Dialog")
.setCancelable(false)
.setView(view)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
Hope this helps!
Upvotes: 0