I have coded a custom Dialog, with a custom layout.
It has a cancel
and a save
button and you can set up also gravity on the device's screen (bottom) and define the width and height of the dialog.
private void showDialog(final String scanContent, final String currentTime, final String currentDate) {
LayoutInflater linf = LayoutInflater.from(this);
final View inflator = linf.inflate(R.layout.dialog_barcode_result_dialog, null);
final Dialog dialog = new Dialog(this, android.R.style.Theme_DeviceDefault_Light_Dialog);
// Setting dialogview
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);
dialog.getWindow().setLayout(375, 350);
window.setLayout(WindowManager.LayoutParams.FILL_PARENT, WindowManager.LayoutParams.FILL_PARENT);
dialog.setTitle(null);
dialog.setContentView(R.layout.dialog_barcode_result_dialog);
dialog.setTitle(getResources().getString(R.string.dialog_title));
dialog.setContentView(inflator);
final Button save = inflator.findViewById(R.id.saveBtn);
final Button cancel = inflator.findViewById(R.id.cancelBtn);
final TextView message = inflator.findViewById(R.id.dialog_message_text);
message.setText(scanContent);
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.cancel();
}
});
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.cancel();
}
});
dialog.show();
}
the dialog layout xml file is:
<?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:minWidth="350dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textSize="16sp"
android:layout_marginBottom="10dp"
android:id="@+id/dialog_message_text"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<Button
android:id="@+id/cancelBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel" />
<Button
android:id="@+id/saveBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_save" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>