ScrollView Не работает, когда клавиатура отображается в android
Моя проблема в том, что клавиатура открыта. scrollview не работает. Значит, когда у меня есть тема android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
scrollview не работает. Когда у меня есть тема android:theme="@android:style/Theme.Black.NoTitleBar"
и удаляю это из манифеста android:windowSoftInputMode="adjustResize"
, тогда scrollview работает отлично. Но моя тема приложения android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
.
Это моя деятельность
package com.example.demo;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Это мой xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn3" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn4" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn5" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn3" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn4" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn5" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Это мой манифест
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
<activity
android:name="com.example.demo.MainActivity"
android:windowSoftInputMode="adjustResize" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Пожалуйста, помогите мне. Спасибо заранее.
Ответы
Ответ 1
У меня такая же проблема. Полноэкранный режим предотвращает прокрутку.
В бетоне я проверил несколько FLAGS и LAYOUTS.
Они работают и не препятствуют прокрутке:
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_FULLSCREEN
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
Это предотвращает прокрутку и не работает:
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Итак, у меня получилось обходное решение, заняло несколько дней, но оно работает!
-
Выберите тему, которая не является полноэкранным в файле manifest.xml, например:
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
-
Добавьте этот код, который сделает вашу деятельность в полноэкранном режиме
private static View systemUIView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(R.layout.rootlayout); //your layout with the scrollview
// hide the native android navigation and status bar
systemUIView = getWindow().getDecorView();
hideSystemUI();
if (android.os.Build.VERSION.SDK_INT >= 19) {
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(
new OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
if (visibility == 0) {
hideSystemUI();
}
}
});
}
// ... here comes my whole code...
}
@Override
public void onResume() {
super.onResume();
hideSystemUI();
}
public void hideSystemUI() {
systemUIView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
Панель управления и панель навигации исчезают. Причина этого в том, что я установил IMMERSIVE_STICKY. Это целая работа, чтобы проверить все это. Надеюсь, это поможет вам всем или, по крайней мере, даст вам правильное направление.
Помните, что Fullscreen-Theme всегда будет препятствовать прокрутке, пока идет экранная клавиатура. Я ссылаюсь на Android 4.4 (KitKat).
Ответ 2
применить вид прокрутки с родительским макетом.
попробуйте это, это может вам помочь.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn3" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn4" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn5" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn1" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn2" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn3" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn4" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="btn5" />
</LinearLayout>
</ScrollView>
Ответ 3
В манифесте:
android:windowSoftInputMode="adjustPan|stateVisible"
В макете xml внизу всего дочернего макета scrollview задано одно текстовое представление, например
<ScrollView
android:id="@+id/driverLoginScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="false"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical">
.
.
.
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:focusable="false"
android:textIsSelectable="false" />
</LinearLayout>
</ScrollView>