Android 自定义对话框在一个活动中显示,在另一个活动中未显示,没有错误
我有个小问题。在“我的一个活动”(MainActivity)对话框窗口(dialog_exit)中显示时没有出现任何问题,但在“其他活动”(MenuR)中它(dialog_podaj)没有出现问题。当我点击一个按钮,屏幕就会变暗,仅此而已。没有别的事情发生。没有显示错误。 我认为代码是一样的,但我可能错了。我看不出我的第二个古代密码有任何错误,所以这就是我请求你帮助的原因 这是第一个活动(MainActivity),对话框窗口在此工作:Android 自定义对话框在一个活动中显示,在另一个活动中未显示,没有错误,android,dialog,Android,Dialog,我有个小问题。在“我的一个活动”(MainActivity)对话框窗口(dialog_exit)中显示时没有出现任何问题,但在“其他活动”(MenuR)中它(dialog_podaj)没有出现问题。当我点击一个按钮,屏幕就会变暗,仅此而已。没有别的事情发生。没有显示错误。 我认为代码是一样的,但我可能错了。我看不出我的第二个古代密码有任何错误,所以这就是我请求你帮助的原因 这是第一个活动(MainActivity),对话框窗口在此工作: public class MainActivity ext
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);
}
}
以下是一系列主要活动:
<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>
MenuR布局代码:
<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>
<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>
<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>
和对话框_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/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>
<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>
<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>
对话框大小是否存在差异?注销对话框-一个小对话框和对话框\u podaj
是一个全屏对话框吗?所有对话框的大小都差不多,只是普通的对话框。。。。我做过类似的应用程序。并且有相同的代码(我可以说它几乎是复制粘贴的),在这个旧的应用程序中,对话框窗口可以完美地工作。就在那一次活动中,Android Studio不想合作,也不显示对话框窗口。。。我想这是因为指导方针吗?这是我能看到的唯一区别。(对不起我的英语,这不是我的母语…)这不是指导原则错误(我检查了这个)@M.Deer-你能提供你的反馈吗?我希望它对你有用。