사용자가 대화 상자의 버튼을 클릭하지 않으면 항상 집중되는 안드로이드 대화 상자를 어떻게 만들 수 있습니까?안드로이드의 배경 레이아웃이 아닌 대화 상자에만 포커스가 있습니다.
대화 상자는 팝업처럼 작동하며 닫지 않고 배경 레이아웃을 클릭 할 때 비활성화됩니다.
사용자가 대화 상자의 버튼을 클릭하지 않으면 항상 집중되는 안드로이드 대화 상자를 어떻게 만들 수 있습니까?안드로이드의 배경 레이아웃이 아닌 대화 상자에만 포커스가 있습니다.
대화 상자는 팝업처럼 작동하며 닫지 않고 배경 레이아웃을 클릭 할 때 비활성화됩니다.
Sample Code
귀하의 활동에서 사용해 볼 수 있습니다.
당신은 문서 찾을 수 있습니다 here
Dialog myDialog = new AlertDialog.Builder(getActivity())
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(title)
.setCancelable(false)
.setPositiveButton(R.string.alert_dialog_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Do your stuff
}
}
)
.setNegativeButton(R.string.alert_dialog_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Do your stuff
}
}
)
.create();
감사합니다. 필요한 것은 .setCancelable (false)입니다. 4 분 후에 답을 수락합니다. – kitokid
@kitokid 귀하의 코드에 무엇이 빠졌는지 몰랐으므로 대화 작성을위한 전체 스 니펫을 작성했습니다. :) –
왜, 당신이 당신의 자신의 대화 상자를 만들
final Dialog dialog = new Dialog(DialogBoxActivity.this);
dialog.setContentView(R.layout.maindialog);
dialog.setTitle("This is dialog box");
dialog.setCancelable(true);
//set up text
TextView text = (TextView) dialog.findViewById(R.id.TextView01);
text.setText("Are you sure you want to exit");
//set up button
Button yes = (Button) dialog.findViewById(R.id.yes);
yes.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
finish();
}
});
Button no = (Button)dialog.findViewById(R.id.no);
no.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
dialog.dismiss();
}
});
dialog.show();
해달라고도
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:id="@+id/ScrollView01"
android:layout_width="192dp"
android:layout_height="48dp"
android:layout_below="@+id/ImageView01" >
<TextView android:text="@+id/TextView01" android:id="@+id/TextView01"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<Button
android:id="@+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="24dp"
android:text=" Yes " />
<Button
android:id="@+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:layout_toRightOf="@+id/yes"
android:text=" No " />
</RelativeLayout>
</LinearLayout>
그것과 같은 레이아웃, maindialog.xml을 정의 대화 상자에 대한 사용자 정의 레이아웃을 생성 할 수 있지만 톤 클릭.
대화 상자 외부를 터치하면 AlertDialog가 취소되는 경우이 코드를 AlertDialog에 넣으면 외부 터치를 통해 취소 할 수 있습니다.
코드 : 또한 BackPress 키
코드로 대화 상자를 닫습니다 중지 다른 속성을 설정할 수 있습니다
dialog.setCanceledOnTouchOutside(false); // Where dialog is the object of your AlertDialog
:
dialog.setCancelable(false);
그것은 당신을 도울 것입니다 바랍니다.
모든 검색어에 대한 의견입니다.
코딩 즐기기. :)
우리는 코드를 가질 수 있습니까? Please Please !! ? –
나는 경보 대화 상자가 기본적으로이 모든 속성을 가지고 있다고 생각한다. –
그래, @ imrankhan이 맞다. 경고 대화 상자에는 동일한 속성이 있습니다. –