I need to create activity which will contain text input (EditText) and some list of items (TextView-s) under that input. The status bar wont be visible, only navigation bar will be visible. After user clicks on EditText, soft keyboard needs to be displayed, but system UI cant be changed (status bar invisible, navigation bar visible). User has to be still able to scroll to the bottom of ListView (to be able to see the last item in the ListView), while softkeyboard is still visible.
The problem is that I am not able to achieve this behavior - status bars stays hidden only if I use flag WindowManager.LayoutParams.FLAG_FULLSCREEN. But in that case content of activity wont be resized and keybord will cover few TextView-s at the bottom of ListView. I found many similar questions here, but none of them describes my situation (invisible status bar + visible soft keyboard + visible all layout content of activity).
It seems that when is keyboard displayed, android will change some flags of UI, so I tried to reset them back afterwards, but without success - see usage of method "hideStatusBar()".
Here is my code:
Layout:
<?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">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="EditText"/>
<ListView
android:id="@+id/test_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Activity:
public class TestActivity extends Activity {
private ListView listView;
private ArrayAdapter<View> adapter;
private List<View> views = new ArrayList<>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_content);
adapter = new ArrayAdapter<View>(this, 0, views) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return views.get(position);
}
};
listView = (ListView) findViewById(R.id.test_list_view);
listView.setAdapter(adapter);
TextView textView = null;
for (int i = 0; i < 50; i++) {
textView = new TextView(this);
textView.setText("textView - " + i);
views.add(textView);
}
final View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
hideStatusBar("onSystemUiVisibilityChange");
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
hideStatusBar("onSystemUiVisibilityChange (delayed)");
}
}, 500);
}
});
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
hideStatusBar("onWindowFocusChanged");
}
public void hideStatusBar(String place) {
Log.i("test", "hideStatusBar - " + place);
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
decorView.setSystemUiVisibility(uiOptions);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
Activity definition in AndroidManifest.xml:
<activity
android:name="TestActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Edit:
I was probably not clear enough. This is what looks like my layout without displayed soft-keyboard: img1
This is what it looks like after soft-keyboard is displayed and line "getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);" is commented: img2. Status bar is visible (that is the problem) and you can scroll to the last item in ListView.
If I add flag "WindowManager.LayoutParams.FLAG_FULLSCREEN" to the window, status bar becomes transparent but still visible and you cant sroll to the last item in ListView: img3
I tried to find answer here but everyone suggests to use fullscreen layout by one of following ways
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
or using fullscreen theme
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
or by setting window flags
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Each of these solutions have one problem: keboard is displayed above/over the layuout and that is why it is not possible to scroll to the last item in ListView.