0

I write a fragment and set let android:windowSoftInputMode in the androidmanifest.xml as default. But the Activity who uses it set its android:windowSoftInputMode as stateHidden|adjustResize, so the soft keyboard will not dismiss as supposed, but the host activity would not like to change their attribute. I try to use

((Activity)sContext).getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

but it does not work. I think fragment does not have the permission to change this attribute of activity, right? Can I use default value in my fragment and does not effect others in the activity?

newszer
  • 440
  • 1
  • 4
  • 23

1 Answers1

0

For getting an activity from fragment you can use getActivity() method by which you can get an parent activity.

Try using following,

getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Lalit Dhameliya
  • 348
  • 3
  • 8
  • It does not work, and the sContext is the activity, what I care most is that does fragment has the permission to do this. – newszer Dec 15 '16 at 11:05