我的AlertDialog存在一些问题。单击ImageButton后显示AlertDialog,问题是AlertDialog窗口的大小 - 它与布局内部不匹配导致视图被切断。尝试了我在这里找到的所有东西,没有任何影响。
AlertDialog.xml代码
<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" />
和我的AlertBuilder代码
@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();
}
答案 0 :(得分:1)
试试这个
删除
<android.support.constraint.ConstraintLayout...
标记并用RelativeLayout
替换整个xml。
答案 1 :(得分:0)
完成。我没有在任何地方找到解决我的问题的方法,所以我在这里发布并希望它能帮助某人。
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>
和我的alertdialog建设者
@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();
}
愿部队与你在一起