Android 颤振键盘使文本字段隐藏
我是个新手。我已经添加了一个带有文本字段的表单,当我点击文本字段,键盘出现时,文本字段上升 这是我的代码:Android 颤振键盘使文本字段隐藏,android,ios,mobile,flutter,Android,Ios,Mobile,Flutter,我是个新手。我已经添加了一个带有文本字段的表单,当我点击文本字段,键盘出现时,文本字段上升 这是我的代码: Widget build(BuildContext context) { MediaQueryData mediaQuery = MediaQuery.of(context); return new Scaffold( body: new Container( color: Colors.purple, constraints: new BoxConstra
Widget build(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
return new Scaffold(
body: new Container(
color: Colors.purple,
constraints: new BoxConstraints.expand(),
padding: EdgeInsets.only(top: 10.0,left: 10.0,right: 10.0, bottom: mediaQuery.viewInsets.bottom, ),
child: SingleChildScrollView(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: 12.0),
Text(
'What is your Business Name?',
style: TextStyle(fontSize: 24.0),
),
AppForm(),
],
),
padding: EdgeInsets.only(left: 10.0,right: 10.0, bottom: mediaQuery.viewInsets.bottom),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
color: Colors.white,
),
)
)
),
);
}
知道怎么解决吗?我就是这样。你肯定是在另一个脚手架里包裹一个脚手架。在你的flatter应用程序中应该只有一个scaffold小部件,即主布局。简单地移除你所有的祖先支架,只保留一个支架。不要把脚手架包在另一个脚手架上。尽管如此,你还是可以把脚手架包在一个容器里 确保在main.dart文件中未执行以下操作:- ✖✖
return Scaffold(
body : YourNewFileName(),
);
尽管有上述代码,请执行以下操作:-
✔✔
修复了文本字段被键盘隐藏的问题
resizeToAvoidBottomPadding
已弃用
改为使用
resizeToAvoidBottomInset:true
此答案不是针对上述问题的,但对于那些仍在使用覆盖所选文本字段的键盘时遇到问题的人,无论他们做什么,都可能有用。当我试图解决这样一个问题时,我进入了这个页面
在出现问题之前,我一直在做一些改变,试图改进我启动应用程序时的启动屏幕。根据某人的建议,我在android/app/src/main/res/values文件夹中styles.xml文件的
部分包含了以下行
<item name="android:windowFullscreen">true</item>
true
这产生了意想不到的效果,当显示键盘时,停止主应用程序中向上滚动的任何字段。这对一些人来说可能是显而易见的,但对我来说不是
希望此信息能帮助他人。您可以简单地将您希望永远不会被键盘隐藏的小部件包装在填充中,如下所示:
Padding(
child: YourWidget()
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom));
只需将你的身体代码剪切粘贴到这个-
SingleChildScrollView(
child: Stack(
children: <Widget>[
// your body code
],
),
),
SingleChildScrollView(
子:堆栈(
儿童:[
//你的身体密码
],
),
),
如果您使用的是
Scaffold
,那么使用SingleChildScrollView
例如:
...
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
TextField(),
TextField(),
TextField(),
],
),
),
);
...
。。。
返回脚手架(
正文:SingleChildScrollView(
子:列(
儿童:[
TextField(),
TextField(),
TextField(),
],
),
),
);
...
这真是我的救命恩人。
现在脚手架将变成可滚动的。对我的修复与GrahamD的回答类似 我使用一个具有.全屏的父级来声明自己的主题,例如:
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar.Fullscreen">
<item name="android:windowBackground">@android:color/white</item>
</style>
@android:彩色/白色
因为它应该可以使用全屏主题并具有正常的聊天应用程序行为。true
<item name="android:windowFullscreen">true</item>
从中删除上面的行
android/app/src/main/res/values/styles.xml
使我的应用程序固定到输入字段自动向上滚动进入视图,可在键盘上打开
谢谢@GrahamD
我通过添加一个
Stack()
作为我的Scaffold()
的主体来解决上述问题,这允许TextField()
对象在软键盘上方向上滑动。最初,我对主体使用了SingleChildScrollView()
,这导致TextField()
对象被软键盘遮挡
对我有效的解决方案:
child: Scaffold(
resizeToAvoidBottomInset: true,
body: Stack(
children: <Widget>[]
child:Scaffold(
resizeToAvoidBottomInset:true,
主体:堆栈(
儿童:[]
您应该将SingleChildsColView添加到脚手架中,并将reverse:true添加到SingleChildsColView中
Scaffold(
body: SingleChildScrollView(
reverse: true,
child: Container()));
我也遇到了同样的问题,我也使用了
SingleChildScrollView
,但这并没有解决我的问题
Column(
childern:[
Expaned(
child:SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
flex:1
),
doneButtonWidget()//this button align with the bottom of the screen.
]
)
我的问题在这段代码中累积
Stack(
childern:[
SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
doneButtonWidget()//this button align with the bottom of the screen.
]
)
为了解决这个问题,我遵循这个,它解决了我的问题
Column(
childern:[
Expaned(
child:SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
flex:1
),
doneButtonWidget()//this button align with the bottom of the screen.
]
)
resizeToAvoidBottomInset默认为true 返回脚手架( resizeToAvoidBottomInset:false
我将其设置为false,效果良好您是否有最新版本的颤振?颤振医生怎么说?这是我的颤振医生输出。医生摘要(要查看所有详细信息,请运行颤振医生-v):[√] 颤振(通道测试版,v0.5.1,在Microsoft Windows[Version 10.0.17134.165]上,语言环境为美国英语)[√] Android工具链-为Android设备开发(Android SDK 28.0.0)[√] Android Studio(3.1版)[!]VS代码,64位版本(1.25.1版)[!]已连接的设备!没有可用的设备!医生发现了两类问题。我建议您转到通道颤振主控<代码>颤振主控<代码>当前位于<代码>v5.7代码>的通道颤振主控<代码>并使用<代码>颤振清理代码>和<代码>使缓存无效并重新启动代码>清理您的项目。看到了吗???@Nirodya Gamage你能发布main.dart文件吗?这样我就可以检查错误在哪里了?很抱歉你是正确的!我在背景上发现了另一个脚手架。我移除了一个,它工作了。非常感谢!太好了。因为同样的事情发生在我身上,我就是这样解决的。我在脚手架里面有一个脚手架。我需要添加Tabbarview。sol是什么解决方案。Tab bar也可以添加一个脚手架@dominic_torreto。目前,脚手架中的脚手架会给你带来一些类似的错误。因此你应该改变你设计应用程序的结构。谢谢你,这对你很有帮助。我花了很多时间搜索这个问题,但没有任何效果。但我不会取消了解为什么全屏显示真的会导致此错误。非常感谢您,我尝试了所有小部件的技巧,但没有任何效果。非常感谢您。我只是做了所有必要的工作来修复它,并且刚刚意识到它在启动屏幕实现之前工作正常。这解决了我在整个应用程序中的问题。这非常棒。设置
resizetoavidobotomInset:true
对于脚手架,将使用此.resize将视图调整到键盘上方的区域内
Stack(
childern:[
SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
doneButtonWidget()//this button align with the bottom of the screen.
]
)
Column(
childern:[
Expaned(
child:SingleChildScrollView(),// In scollView i have textFeild when keyboard opens doneButton hide the textFeild.
flex:1
),
doneButtonWidget()//this button align with the bottom of the screen.
]
)