I have a fragment with EditText and add it into the layout using transactions. But if I rotate to landscape the soft keyboard disappears.
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (getSupportFragmentManager().findFragmentById(R.id.fragmentContainer) == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, new FragmentWithEditText())
.commit();
}
}
}
I want keyboard state still unchanged after rotate using fragment transactions. Because if I don't use transactions, but add a fragment straight in the layout, the keyboard not disappeared.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:tag="fragmentWithKeyboard"
android:name="com.test.FragmentWithEditText"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
I already tried to use android:windowSoftInputMode="stateUnchanged"
or android:configChanges="keyboardHidden|orientation"
, but didn't help.
Also I wrote a sample app with this behavior https://github.com/anton9088/FragmentAndKeyboard
Similar questions: