I need to create an activity that will contain text input (EditText) and some list of elements (TextView-s) under this input. The status bar will not be visible, only the navigation bar will be displayed. After the user clicks on EditText, a soft keyboard should be displayed, but the system user interface cannot be changed (the status bar is invisible, visible navigation bar). The user should still be able to scroll to the bottom of the ListView (in order to be able to see the last item in the ListView) while the on-screen bar is still visible.
The problem is that I cannot achieve this behavior - the status bars remain hidden only if I use the WindowManager.LayoutParams.FLAG_FULLSCREEN flag. But in this case, the content of the activity will not be changed, and the keybord will span several TextViews at the bottom of the ListView. Here I found a lot of similar questions, but none of them describes my situation (invisible status bar + visible soft keyboard + all layout of activity content is visible).
It seems that when the keyboard is displayed, the android changes some UI flags, so I tried to return to reset after this, but without success - see using the "hideStatusBar ()" method.
Here is my code:
Markup:
<?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); } }
Determining activity 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 it looks like my layout without a soft keyboard displayed: img1
It looks like as soon as the soft keyboard is displayed and the line is “getWindow (). AddFlags (WindowManager.LayoutParams.FLAG_FULLSCREEN); commented out: img2 . The status bar is visible (this is a problem) and you can go to the last item in the ListView.
If I add the “WindowManager.LayoutParams.FLAG_FULLSCREEN” flag to the window, the status bar will become transparent, but still visible, and you cannot scroll the last item in the ListView: img3
I tried to find the answer here, but everyone suggests using a full-screen layout in one of the following ways.
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
or using a fullscreen theme
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
or by setting the checkboxes of the window
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Each of these solutions has one problem: keboard is displayed above / above layuout, and therefore it is not possible to scroll to the last item in a ListView.