简体   繁体   中英

Android- AlertDialog doesn't move above keyboard when it toggle in FullscreenActivity

I have dialog which has a EditText get overlapped by the soft input keyboard.I've tried all posts i could like

 dialog.getWindow().setSoftInputMode(ADJUST_RESIZE)

and set theme for dialog but neither of them work. I think my Fullscreen Activity has changed something but I have no idea what it is

 View layout= LayoutInflater.from(context).inflate(R.layout.add_bookmark_dialog_layout,null);
    final EditText note=(EditText)layout.findViewById(R.id.bookmark_note);
    TextView page= (TextView)layout.findViewById(R.id.bookmark_page);
    TextView file=(TextView)layout.findViewById(R.id.bookmark_file);
    page.setText(String.valueOf(currentPage));
    file.setText(fileName);
    AlertDialog.Builder builder=new AlertDialog.Builder(context).setView(layout).setTitle("Add New Bookmark").setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Bookmark newBookmark= db.addBookmark(currentPage,note.getText().toString(),fileName);
            adapter.add(newBookmark);
        }
    }).setNegativeButton("Cancel",null);
    AlertDialog dialog=builder.create();
   //Not working : dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    dialog.show();

Here my AndroidManifest.xml

 <application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity" android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"  />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
//where dialog pop up
    <activity
        android:name=".ReadingActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_reading"
        android:parentActivityName=".MainActivity"
        android:theme="@style/FullscreenTheme"></activity>
</application>

Add below code in manifest

android:windowSoftInputMode="adjustResize"

So final code is

 <activity
        android:name=".ReadingActivity"
        android:configChanges="orientation|keyboardHidden|screenSize"
        android:label="@string/title_activity_reading"
        android:windowSoftInputMode="adjustResize"
        android:parentActivityName=".MainActivity"
        android:theme="@style/FullscreenTheme"></activity>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM