program tip

Android 대화 상자 : 제목 표시 줄 제거

radiobox 2020. 8. 8. 12:17
반응형

Android 대화 상자 : 제목 표시 줄 제거


나는 내가 원인을 정확히 찾아 낼 수없는 이상한 행동을하고있다.

클래식이있는 내 앱이 있습니다.

requestWindowFeature(Window.FEATURE_NO_TITLE);

제목 / 상태 표시 줄을 제거합니다.

그런 다음 사용자가 정보 (이름 등)를 입력 할 수있는 대화 상자를 만듭니다.

물리적 키보드를 사용하면 문제가 없지만 가상 키보드를 사용할 때 이상한 동작이 발생합니다.

가상 키보드의 키를 누를 때마다 제목 / 상태 표시 줄이 다시 나타나 모든 키보드 레이아웃을 밀고 다시 사라집니다 (애플리케이션을 시작할 때의 애니메이션처럼)

다음은 몇 가지 코드입니다.

        dialog = new Dialog(context);
        dialog.setContentView(R.layout.logindialog);
        dialog.setTitle("Login:");

        WindowManager.LayoutParams a = dialog.getWindow().getAttributes();

//      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

        a.dimAmount = 0;
        dialog.getWindow().setAttributes(a);

        dialog.setCancelable(true);
        dialog.getWindow().setLayout(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);

그리고

dialog.show();

나는 시도했다

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

하지만 내 앱이 충돌합니다.

여기에 xml이 있습니다

    <TextView android:id="@+id/LoginText"
        android:gravity="fill"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Login:">
    </TextView>         
    <EditText android:id="@+id/LoginEdit"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="jason"
        android:layout_width="200sp"/>
    <TextView android:id="@+id/PasswordText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Password:">
    </TextView>         
    <EditText android:id="@+id/PasswordEdit"
        android:layout_height="wrap_content"
        android:singleLine="true"
        android:text="welcome"
        android:layout_width="200sp"
        android:password="true"/>
<LinearLayout 
    android:id="@+id/test2"
    android:gravity="center_horizontal"
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<Button android:id="@+id/LoginButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Login" />
<Button android:id="@+id/CreateButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Create" />
<Button android:id="@+id/CancelLogin"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:text="Cancel" />
</LinearLayout>/>


사용하다,

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
dialog.setContentView(R.layout.logindialog);

styles.xml에서 새 스타일 만들기

<style name="myDialog" parent="android:style/Theme.Dialog">
   <item name="android:windowNoTitle">true</item>
</style>

그런 다음 매니페스트에 추가하십시오.

 <activity android:name=".youractivity" android:theme="@style/myDialog"></activity>

위의 모든 답변이 AppCompatDialog에서 작동하지 않습니다.

AppCompatDialog 를 사용하는 경우 이것을 시도하십시오

중요 참고 : setContentView를 호출하기 전에이를 설정하십시오.

dialog.supportRequestWindowFeature (Window.FEATURE_NO_TITLE);


여기 대화 상자에 표시된 XML을 작성하십시오. activity_no_title_dialog입니다.

final Dialog dialog1 = new Dialog(context);
dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog1.setContentView(R.layout.activity_no_title_dialog);
dialog1.show();

제목 표시 줄을 표시하지 않도록 Android 매니페스트 파일에 테마를 정의 할 수도 있습니다.

android:theme="@android:style/Theme.Light.NoTitleBar"제목 표시 줄을 표시하고 싶지 않은 활동에서 테마 정의하기 만하면 됩니다.

예:-

    <uses-sdk android:minSdkVersion="4"android:targetSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".splash"
              android:label="@string/app_name" android:screenOrientation="portrait"
              android:theme="@android:style/Theme.Light.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

<activity android:name="main" android:screenOrientation="portrait" android:theme="@android:style/Theme.Light.NoTitleBar"></activity>


사용자 정의보기를 사용하는 경우 이와 같은 컨텐츠보기를 추가하기 전에 창 기능을 요청하십시오.

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(view);
dialog.show();

setcontentview 전에 아래 코드를 사용하십시오.

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
dialog.setContentView(R.layout.custom_dialog);

참고 :- 위 코드는 위 코드를 사용해야합니다.dialog.setContentView(R.layout.custom_dialog);

XML에서 테마 사용

android:theme="@android:style/Theme.NoTitleBar"

또한 styles.xml :

<style name="hidetitle" parent="android:style/Theme.Dialog">
   <item name="android:windowNoTitle">true</item>
</style>

그리고:

Dialog dialog_hidetitle_example = new Dialog(context, R.style.hidetitle);

저는 Android 초보자이며 제목 표시 줄을 제거하려는이 질문을 발견했습니다.

I'm using an activity and displaying it as a dialog. I was poking around with themes and came across a useful bit of default theming.

Here's the code from my AndroidManifest.xml that I was using when the title bar was showing:

<activity
    android:name=".AlertDialog"
    android:theme="@android:style/Theme.Holo.Dialog"

    >

</activity>

Here's the change that got me my desired result:

<activity
    android:name=".AlertDialog"
    android:theme="@android:style/Theme.Holo.Dialog.NoActionBar"

    >

</activity>

As I said, I'm still new to Android, so this may have undesirable side-effects, but it appears to have given me the outcome I wanted, which was just to remove the title bar from the dialog.


I'm using next variant:

Activity of my custom Dialog:

public class AlertDialogue extends AppCompatActivity {

    Button btnOk;
    TextView textDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_alert_dialogue);

        textDialog = (TextView)findViewById(R.id.text_dialog) ;
        textDialog.setText("Hello, I'm the dialog text!");

        btnOk = (Button) findViewById(R.id.button_dialog);
        btnOk.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
}

activity_alert_dialogue.xml:

<?xml version="1.0" encoding="utf-8"?>
<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="300dp"
    android:layout_height="wrap_content"
    tools:context=".AlertDialogue">

    <TextView
        android:id="@+id/text_dialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="24dp"
        android:text="Hello, I'm the dialog text!"
        android:textColor="@android:color/darker_gray"
        android:textSize="16dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button_dialog"
        android:layout_width="wrap_content"
        android:layout_height="36dp"
        android:layout_margin="8dp"
        android:background="@android:color/transparent"
        android:text="Ok"
        android:textColor="@android:color/black"
        android:textSize="14dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/text_dialog" />


</android.support.constraint.ConstraintLayout>

Manifest:

<activity android:name=".AlertDialogue"
            android:theme="@style/AlertDialogNoTitle">
</activity>

Style:

<style name="AlertDialogNoTitle" parent="Theme.AppCompat.Light.Dialog">
        <item name="android:windowNoTitle">true</item>
</style>

With next variant I have no reaction:

dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before     
dialog.setContentView(R.layout.logindialog);

So, I try to use next:

dialog.supportRequestWindowFeature(Window.FEATURE_NO_TITLE); //before     
dialog.setContentView(R.layout.logindialog);

This variant work excellent.


This worked for me.

Dailog dialog = new Dialog(MyActivity.this, R.style.dialogstyle);

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="dialogstyle" parent="android:style/Theme.Dialog">
        <item name="android:windowBackground">@null</item>
        <item name="android:windowNoTitle">false</item>
    </style>
</resources>

You can try this simple android dialog popup library. It is very simple to use on your activity.

When submit button is clicked try following code after including above lib in your code

Pop.on(this)
   .with()
   .title(R.string.title) //ignore if not needed
   .icon(R.drawable.icon) //ignore if not needed
   .cancelable(false) //ignore if not needed
   .layout(R.layout.custom_pop)
   .when(new Pop.Yah() {
       @Override
       public void clicked(DialogInterface dialog, View view) {
           Toast.makeText(getBaseContext(), "Yah button clicked", Toast.LENGTH_LONG).show();
       }
   }).show();

Add one line in your gradle and you good to go

dependencies {
    compile 'com.vistrav:pop:2.0'
}

**write this before adding view to dialog.**

dialog1.requestWindowFeature(Window.FEATURE_NO_TITLE);

참고URL : https://stackoverflow.com/questions/6263639/android-dialog-removing-title-bar

반응형