Layout file:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/popupCategoriesLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_categories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nestedScrollingEnabled="true"
android:paddingTop="8dp"
android:scrollbars="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/popu_category_info"
/>
<ImageView
android:id="@+id/imageViewPopupCategoryInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
app:layout_constraintBottom_toBottomOf="@+id/popu_category_info"
app:layout_constraintEnd_toStartOf="@+id/popu_category_info"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_info_outline_orange_24dp" />
<TextView
android:id="@+id/popu_category_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:background="@color/popup_warning_category"
android:paddingStart="8dp"
android:text="@string/warning_category_info"
android:textColor="@color/white"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
So I want info label at the top of my dialog + scrollable list. Code to show dialog:
CategoryGroupAdapter gropupAdapter = new CategoryGroupAdapter(categoryGroups);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
View convertView = LayoutInflater.from(MainActivity.this).inflate(R.layout.popup_category, null);
RecyclerView list = convertView.findViewById(R.id.list_categories);
list.setLayoutManager(new LinearLayoutManager(MainActivity.this));
list.setHasFixedSize(false);
list.setAdapter(gropupAdapter);
gropupAdapter.collapseAll();
AlertDialog d = alertDialog.setView(convertView).setCancelable(true).setTitle(getString(R.string.category_dialog_title)).show();
As the result, I am getting my list truncated at the bottom if entire list has no room to display all items. It seems it's truncated of the info label height (but I can't set fixed info label height, because it needs to show all text on all devices with various dpi).
Any ideas how to display my dialog correctly?
Screenshot:
Create an custom dialog extending Dialog fragment and passed required data through constructor and set them on dialog UI as per your need.
public class AlertDialogFragment extends DialogFragment {
Context context;
public AlertDialogFragment(){
}
//Create a multiple constructor on your need
onStart(){
//Set your logic if any like button color or UI on flag
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.customalertstyle)
// set dialog icon
// set Dialog Title
.setTitle(title)
// Set Dialog Message
.setItems(items, itemClickListner)
.setMessage(msg)
// positive button
.setCancelable(false)
.setPositiveButton(positiveBtnText, positiveClickListner)
.setOnKeyListener(keyListener)
.setNegativeButton(negativeBtnText, negativeClickListner);
}
@Override
public void show(FragmentManager manager, String tag) {
//to catch the exception while app is in background and dialog
try {
super.show(manager, tag);
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
@Override
public void dismiss() {
super.dismiss();
}
}
Don't forgot to use support dialog fragment as another one is deprecated.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.