Reputation: 71
I have some problems with my AlertDialog. AlertDialog is show after I click ImageButton and the problem is size of AlertDialog window - it doesn't match to layout inside which causes the view to be cut off. Tried everything i've found here and no effects.
AlertDialog.xml code
<android.support.constraint.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:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/price"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/greater_than"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:text="@string/greater_than"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/price"
app:layout_constraintStart_toEndOf="@+id/price" />
<TextView
android:id="@+id/less_than"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/less_than"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/price"
app:layout_constraintTop_toBottomOf="@+id/price" />
<EditText
android:id="@+id/greater_than_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="numberDecimal"
app:layout_constraintBottom_toBottomOf="@+id/greater_than"
app:layout_constraintStart_toEndOf="@+id/greater_than"
app:layout_constraintTop_toTopOf="@+id/greater_than" />
<EditText
android:id="@+id/less_than_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="numberDecimal"
app:layout_constraintBottom_toBottomOf="@+id/less_than"
app:layout_constraintStart_toEndOf="@+id/less_than"
app:layout_constraintTop_toTopOf="@+id/less_than" />
<CheckBox
android:id="@+id/notification_checkBox"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/alaram_notification"
app:layout_constraintStart_toEndOf="@+id/price"
app:layout_constraintTop_toBottomOf="@+id/less_than_edit" />
and my AlertBuilder code
@Override
public void alarmOnClick(View v, int position) {
View prompt = getLayoutInflater().inflate(R.layout.popupdialog, null);
EditText biggerThanEdit = prompt.findViewById(R.id.greater_than_edit);
EditText lessThanEdit = prompt.findViewById(R.id.less_than_edit);
TextView biggerThan = prompt.findViewById(R.id.greater_than);
TextView lessThan = prompt.findViewById(R.id.less_than);
CheckBox notificationCheckBox = prompt.findViewById(R.id.notification_checkBox);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
.setView(prompt)
.setTitle(getString(R.string.set_alarm))
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
// Log.d("mainactivity "," dialog box cancel pasrd-------- \n");
}
});
alertDialogBuilder.show();
}
this is screen from AVD with android 8.
Upvotes: 0
Views: 190
Reputation: 13129
Try this
Remove
<android.support.constraint.ConstraintLayout...
tag and replace the whole xml with RelativeLayout
.
Upvotes: 1
Reputation: 71
Done. I have not found a solution to my problem anywhere, so i post it here and hope it will help someone.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:alertDialogTheme">@style/AlertDialogTheme</item>
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AlertDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
dialoglayout.xml
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/relativeLayout"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="@string/price"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/greater_than"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/greater_than"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/price"
app:layout_constraintStart_toEndOf="@+id/price" />
<TextView
android:id="@+id/less_than"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/less_than"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="@+id/price"
app:layout_constraintTop_toBottomOf="@+id/price" />
<EditText
android:id="@+id/greater_than_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="numberDecimal"
app:layout_constraintBottom_toBottomOf="@+id/greater_than"
app:layout_constraintStart_toEndOf="@+id/greater_than" />
<EditText
android:id="@+id/less_than_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ems="10"
android:inputType="numberDecimal"
app:layout_constraintBottom_toBottomOf="@+id/less_than"
app:layout_constraintStart_toEndOf="@+id/less_than" />
<CheckBox
android:id="@+id/notification_checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:text="@string/alaram_notification"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@+id/less_than_edit"
app:layout_constraintTop_toBottomOf="@+id/less_than_edit" />
</android.support.constraint.ConstraintLayout>
and my alertdialog builder
@Override
public void alarmOnClick(View v, int position) {
View prompt = getLayoutInflater().inflate(R.layout.popupdialog, null);
EditText biggerThanEdit = prompt.findViewById(R.id.greater_than_edit);
EditText lessThanEdit = prompt.findViewById(R.id.less_than_edit);
TextView biggerThan = prompt.findViewById(R.id.greater_than);
TextView lessThan = prompt.findViewById(R.id.less_than);
CheckBox notificationCheckBox = prompt.findViewById(R.id.notification_checkBox);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
.setView(prompt)
.setTitle(getString(R.string.set_alarm) + " " + mData.get(position).getCryptoCurrency() + "/" + mData.get(position).getFiatCurrency())
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
})
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
// Log.d("mainactivity "," dialog box cancel pasrd-------- \n");
}
});
alertDialogBuilder.show();
}
May the Force be with you
Upvotes: 1