当键盘被显示在滚动型机器人不工作 [英] ScrollView Not working when keyboard is showing in android
问题描述
我的问题是,当键盘打开滚动视图无法正常工作。基本上意味着,当我有主题安卓主题=@安卓风格/ Theme.Black.NoTitleBar.Fullscreen
滚动视图不工作当我有主题机器人:主题=@安卓风格/ Theme.Black.NoTitleBar
,并从清单安卓删除此:windowSoftInputMode =adjustResize
然后滚动视图完美地工作。但是,我的应用程序的主题是安卓主题=@安卓风格/ Theme.Black.NoTitleBar.Fullscreen
。
My problem is when keyboard is open scrollview is not working. Means basically when I have Theme android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
scrollview is not working When I have theme android:theme="@android:style/Theme.Black.NoTitleBar"
and remove this from manifest android:windowSoftInputMode="adjustResize"
then scrollview is working perfectly. But my app theme is 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>
请帮助我。先谢谢了。
推荐答案
我得到了同样的问题。该fullcreen模式prevents滚动。
I got the same problem. The fullcreen mode prevents the scrolling.
在具体的,我测试了几个标志和布局。 这些工作并没有prevent滚动:
In concrete, i tested several FLAGS and LAYOUTS. These are working and don't prevent scrolling:
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_FULLSCREEN
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
这些都是preventing滚动并不起作用:
These are preventing the scrolling and do not work:
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
所以,我有一个解决办法。最后,我花了一些日子,但它的作品!
So i got a workaround finally, took me some days, but it works!
-
选择一个主题,那就是没有的manifest.xml全屏,例如:
Choose a theme, that is not fullscreen in manifest.xml, e.g.:
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
将此code,使您的活动全屏
Add this code, that makes your activity fullscreen
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);
}
在systembar和导航栏消失。这样做的原因是,因为我已经把IMMERSIVE_STICKY。它是一大堆的工作,各地检验这一切。我希望这可以帮助你的一切,或至少给你正确的方向。
The systembar and navigation bar disappears. The reason for this is, because i have set IMMERSIVE_STICKY. It is whole lot of work to test it all around. I hope this helps you all, or atleast gives you the right direction.
请记住,一个全屏主题总会prevent您滚动而softkeyboard到了。我引用到Android 4.4(奇巧)。
Remember, that a Fullscreen-Theme will always prevent you from scrolling while the softkeyboard is up. I am referencing to Android 4.4(KitKat).
这篇关于当键盘被显示在滚动型机器人不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!