我的问题是键盘打开时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);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的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>
Run Code Online (Sandbox Code Playgroud)
这是我的表现
<?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>
Run Code Online (Sandbox Code Playgroud)
请帮我.提前致谢.
我遇到了同样的问题.全屏模式可防止滚动.
具体来说,我测试了几个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
Run Code Online (Sandbox Code Playgroud)
这些是阻止滚动,不起作用:
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
Run Code Online (Sandbox Code Playgroud)
所以我终于得到了一个解决方法,花了我几天,但它确实有效!
选择一个主题,在manifest.xml中不是全屏,例如:
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar"
Run Code Online (Sandbox Code Playgroud)添加此代码,使您的活动全屏显示
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);
}
Run Code Online (Sandbox Code Playgroud)系统箱和导航栏消失了.原因是,因为我已经设置了IMMERSIVE_STICKY.全面测试它是一大堆工作.我希望这可以帮助你们所有人,或者至少给你一个正确的方向.
请记住,全屏主题将始终阻止您在软键盘启动时滚动.我正在引用Android 4.4(KitKat).
将滚动视图与父布局一起应用。
试试这个可能对你有帮助。
<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>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7422 次 |
| 最近记录: |