Я хочу показать основные c Диалог оповещения с опциями Да Нет, но ни один из методов не работает. Диалоговое окно отображается, но кнопки «ДА НЕТ» нет Я работаю с API 26. Я показываю диалог оповещений в другом упражнении без проблем (ни одно из них не является основным), даже с пользовательскими макетами.
Я использую много диалогов Alerts, но есть пример для go обратного подтверждения.
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setMessage(getResources().getString(R.string.goBackAlert))
.setCancelable(false)
.setPositiveButton(_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ScanRouteActivity.super.onBackPressed();
}
})
.setNegativeButton(_no, null)
.show();
}
Эта функция отлично работает в другом упражнении.
Я также пробовал что-то вроде этого:
AlertDialog.Builder builder =new AlertDialog.Builder(getApplicationContext());
builder.setMessage(getResources().getString(R.string.goBackAlert));
builder.setCancelable(false);
builder.setPositiveButton(_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
QuarantineActivity.super.onBackPressed();
}
});
builder.setNegativeButton(_no, null);
AlertDialog dialog = builder.create();
dialog.show();
AND
final AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setMessage(getResources().getString(R.string.goBackAlert))
.setCancelable(false)
.setPositiveButton(_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
QuarantineActivity.super.onBackPressed();
}
})
.setNegativeButton(_no, null);
final AlertDialog ad = builder.create();
ad.show();
Я уже попробовал следующие операции импорта AlertDialog:
import android.app.AlertDialog;
import androidx.appcompat.app.AlertDialog;
Это XML для действий В этом упражнении все работает нормально:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical"
android:background="@color/colorBackground"
tools:context=".ScanRouteActivity">
<TextView
android:id="@+id/txtVIdRoute"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/TitleFont"
android:text=""/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/menuLabels"
android:layout_gravity="center"
android:id="@+id/txtVCurrentContent" />
<FrameLayout
android:id="@+id/frmScanContent"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
ЗДЕСЬ НЕ РАБОТАЕТ
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical"
android:background="@color/colorBackground"
tools:context=".QuarantineActivity">
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
>
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Select container type:"
android:textColor="@android:color/black"
/>
<Spinner
android:id="@+id/spinQType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:entries="@array/containerType_list"
/>
<Button
android:layout_marginStart="@dimen/default_margin"
android:layout_gravity="center"
android:gravity="center"
android:drawableStart="@drawable/add_photo"
android:id="@+id/btnAddPhoto"
android:enabled="false"
style="@style/circleBtnDark"/>
</TableRow>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/frmQuarantine"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgVPhoto"
android:maxWidth="150dp"
android:minWidth="150dp"
android:maxHeight="150dp"
android:minHeight="150dp"
android:layout_margin="@dimen/default_margin"
android:longClickable="true"
android:visibility="gone"
app:srcCompat = "@drawable/no_image"/>
</LinearLayout>