У меня маленькая проблема. В моем единственном действии (MainActivity) диалоговое окно (dialog_exit) отображается без каких-либо проблем, но в другой интерактивности (MenuR) его (dialog_podaj) нет. Когда я нажимаю кнопку, экран становится темнее, и все. Больше ничего не происходит. Ошибка не отображается. Я думаю, что код тот же, но я могу ошибаться. Я не вижу никакой ошибки во втором коде активности, поэтому я прошу вас о помощи.
Это первое действие (MainActivity), здесь работает диалоговое окно:
public class MainActivity extends AppCompatActivity {
// [...]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manin);
mVisible = true;
mControlsView = findViewById(R.id.fullscreen_content_controlsM);
mContentView = findViewById(R.id.fullscreen_contentM);
mContentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggle();
}
});
MainActButtons();
}
private void MainActButtons(){
Button button_ng = findViewById(R.id.MainActivity_button_NG);
Button button_opcje = findViewById(R.id.MainActivity_button_Opcje);
Button button_wyjscie = findViewById(R.id.MainActivity_button_Wyjscie);
button_ng.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent menu_tryb = new Intent(MainActivity.this, MenuT.class);
startActivity(menu_tryb);
}
});
button_opcje.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, R.string.dialogtxt_opcje, Toast.LENGTH_LONG).show();
}
});
button_wyjscie.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogEXIT();
}
});
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
delayedHide(100);
}
private void DialogEXIT(){
final Dialog dialog_wyjscie = new Dialog(MainActivity.this);
dialog_wyjscie.setCancelable(true);
dialog_wyjscie.setContentView(R.layout.dialog_exit);
Button dialogbutton_wroc = dialog_wyjscie.findViewById(R.id.dialogExitApp_button_WROC);
Button dialogbutton_wyjdz = dialog_wyjscie.findViewById(R.id.dialogExitApp_button_WYJDZ);
dialog_wyjscie.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog_wyjscie.show();
dialogbutton_wroc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog_wyjscie.dismiss();
}
});
dialogbutton_wyjdz.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
dialogbutton_wyjdz.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
finish();
System.exit(0);
return false;
}
});
mContentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog_wyjscie.dismiss();
}
});
}
@Override
public void onBackPressed (){
DialogEXIT();
}
private void toggle() {
if (mVisible) {
hide();
} else {
show();
}
}
private void hide() {
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
mControlsView.setVisibility(View.GONE);
mVisible = false;
mHideHandler.removeCallbacks(mShowPart2Runnable);
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
}
@SuppressLint("InlinedApi")
private void show() {
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mVisible = true;
mHideHandler.removeCallbacks(mHidePart2Runnable);
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
}
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}
Вот макет MainActivity:
<FrameLayout 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:background="#0099cc"
android:id="@+id/fullscreen_contentM"
tools:context=".MainActivity">
<ImageView
android:id="@+id/MainActivity_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="@drawable/bg"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/MainActivity_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="@drawable/logo"
tools:ignore="ContentDescription"/>
<Button
android:id="@+id/MainActivity_button_NG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg_szarp"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/MainActivity_logo"
android:text="@string/text_nowa_gra"
android:textColor="@drawable/button_txt" />
<Button
android:id="@+id/MainActivity_button_Opcje"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg_szarp"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/MainActivity_button_NG"
android:text="@string/text_opcje"
android:textColor="@drawable/button_txt"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/MainActivity_button_Wyjscie"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg_szarp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:text="@string/text_wyjscie"
android:textColor="@drawable/button_txt" />
<LinearLayout
android:id="@+id/fullscreen_content_controlsM"
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"></LinearLayout>
</RelativeLayout>
</FrameLayout>
Вот код макета dialog_exit:
<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/dialogExitApp_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:background="@drawable/dialog_bg"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/dialogExitApp_TV_text"
android:layout_width="325dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:gravity="center"
android:text="@string/text_wyjscie_info"
android:textColor="@color/dialog_exit_txt_color"
android:textSize="20sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<Button
android:id="@+id/dialogExitApp_button_WROC"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:background="@drawable/button_bg"
android:gravity="center"
android:minHeight="35dp"
android:minWidth="120dp"
android:text="@string/text_wroc"
android:textColor="@drawable/button_txt"
android:textSize="17sp" />
<Button
android:id="@+id/dialogExitApp_button_WYJDZ"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_weight="1"
android:background="@drawable/button_bg2"
android:gravity="center"
android:minHeight="35dp"
android:minWidth="120dp"
android:text="@string/text_wyjdz"
android:textColor="@drawable/button_txt2"
android:textSize="17sp" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Все работает без проблем.
И есть код деятельности MenuR. Есть диалоговое окно, которое не работает.
public class MenuR extends AppCompatActivity {
int kontrolkaET;
String textNr = " ";
// [...]
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_r);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
mVisible = true;
mControlsView = findViewById(R.id.fullscreen_content_controlsR);
mContentView = findViewById(R.id.fullscreen_contentR);
mContentView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
toggle();
}
});
MenuRolaButtons ();
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
delayedHide(100);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
private void MenuRolaButtons (){
Button button_t1 = findViewById(R.id.MenuR_button_T1);
Button button_t2 = findViewById(R.id.MenuR_button_T2);
Button button_wsteczR = findViewById(R.id.MenuR_button_Wstecz);
button_t1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent_tY = new Intent(MenuR.this, MapaT.class);
startActivity(intent_tY);
}
});
button_t2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String[] inputStringNr = {null};
final Dialog dialogPodajNr = new Dialog(MenuR.this);
dialogPodajNr.setCancelable(true);
dialogPodajNr.setContentView(R.layout.dialog_podaj);
dialogPodajNr.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
final EditText ETnrRoz = dialogPodajNr.findViewById(R.id.dialogPodajNr_ET_numer);
Button buttonDialogOK = dialogPodajNr.findViewById(R.id.dialogPodajNr_button_OK);
kontrolkaET = 0;
dialogPodajNr.show();
ETnrRoz.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (kontrolkaET == 0) {
ETnrRoz.getText().clear();
kontrolkaET = 1;
}
}
});
ETnrRoz.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
inputStringNr[0] = s.toString();
textNr = inputStringNr[0];
}
@Override
public void afterTextChanged(Editable s) {
}
});
buttonDialogOK.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent_Komp = new Intent(MenuR.this, Komp.class);
intent_Komp.putExtra("numer_r", textNr);
dialogPodajNr.dismiss();
startActivity(intent_Komp);
}
});
}
});
button_wsteczR.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
private void toggle() {
if (mVisible) {
hide();
} else {
show();
}
}
private void hide() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
mControlsView.setVisibility(View.GONE);
mVisible = false;
mHideHandler.removeCallbacks(mShowPart2Runnable);
mHideHandler.postDelayed(mHidePart2Runnable, UI_ANIMATION_DELAY);
}
@SuppressLint("InlinedApi")
private void show() {
mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
mVisible = true;
mHideHandler.removeCallbacks(mHidePart2Runnable);
mHideHandler.postDelayed(mShowPart2Runnable, UI_ANIMATION_DELAY);
}
private void delayedHide(int delayMillis) {
mHideHandler.removeCallbacks(mHideRunnable);
mHideHandler.postDelayed(mHideRunnable, delayMillis);
}
}
Код макета MenuR:
<FrameLayout 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:background="#0099cc"
tools:context=".MenuR"
android:id="@+id/fullscreen_contentR">
<ImageView
android:id="@+id/MenuR_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="1"
android:cropToPadding="false"
android:scaleType="centerCrop"
app:srcCompat="@drawable/bg"
tools:ignore="ContentDescription" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/MenuR_logo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:cropToPadding="false"
android:scaleType="fitXY"
android:src="@drawable/logo"
tools:ignore="ContentDescription"/>
<Button
android:id="@+id/MenuR_button_T1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg_szarp"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/MenuR_logo"
android:text="@string/text_t1"
android:textColor="@drawable/button_txt" />
<Button
android:id="@+id/MenuR_button_T2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg_szarp"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_below="@id/MenuR_button_T1"
android:text="@string/text_t2"
android:textColor="@drawable/button_txt"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/MenuR_button_Wstecz"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_bg_szarp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:text="@string/text_wstecz"
android:textColor="@drawable/button_txt" />
<LinearLayout
android:id="@+id/fullscreen_content_controlsR"
android:layout_width="match_parent"
android:layout_height="35dp"
android:orientation="horizontal"
android:layout_alignParentBottom="true"></LinearLayout>
</RelativeLayout>
</FrameLayout>
И код макета dialog_podaj:
<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/dialogPodajNr_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.Guideline
android:id="@+id/dialogPodajNr_guideline1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.05" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/dialogPodajNr_guideline2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.95" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/dialogPodajNr_guideline2"
app:layout_constraintStart_toStartOf="@id/dialogPodajNr_guideline1"
app:layout_constraintTop_toTopOf="parent"
android:background="@drawable/dialog_bg">
<TextView
android:id="@+id/dialogPodajNr_TV_text"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text_proszeNr"
android:textAlignment="center"
android:textColor="@color/dialog_exit_txt_color"
android:textSize="30sp"/>
<EditText
android:id="@+id/dialogPodajNr_ET_numer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:layout_gravity="center"
android:background="@drawable/edit_text_bg"
android:ems="10"
android:inputType="number"
android:text="@string/text_dots"
android:textSize="27sp"
android:textColor="@color/dialog_exit_txt_color"
android:textAlignment="center"/>
<Button
android:id="@+id/dialogPodajNr_button_OK"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:background="@drawable/button_bg"
android:text="@string/dialogtxt_OK"
android:textAlignment="center"
android:textColor="@drawable/button_txt"
android:textSize="20sp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>