`
ericbaner
  • 浏览: 178364 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

风格为Theme.Dialog的Activity纯代码手写布局里scrollview的问题

 
阅读更多

风格为Theme.Dialog的Activity,即manifest里对Activity加上属性android:theme="@android:style/Theme.Dialog",

 

如果Activity里的所有布局是纯代码所写,不是从layout xml里生成,布局包含一个ScrollView,ScrollView里有很多TextView, EditText这类的小widget, 当用户点击其中一个EditText时,软键盘弹出来盖住了Activity的UI,Activity的UI没有自动缩小显示出scrollview的滚动条, 这是为什么呢?

 

这跟Activity的一个属性有关,即android:windowSoftInputMode:

 

这里设置其为 android:windowSoftInputMode=“stateHidden|adjustResize”即可解决上述我们的问题!

 

具体是什么原因,看以下SDK文档解释就明白了:

 

How the main window of the activity interacts with the window containing the on-screen soft keyboard. The setting for this attribute affects two things:

  • The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
  • The adjustment made to the activity's main window — whether it is resized smaller to make room for the soft keyboard or whether its contents pan to make the current focus visible when part of the window is covered by the soft keyboard.

The setting must be one of the values listed in the following table, or a combination of one "state... " value plus one "adjust... " value. Setting multiple values in either group — multiple "state... " values, for example — has undefined results. Individual values are separated by a vertical bar (| ). For example:

 

<activity
 
android:windowSoftInputMode
=
"stateVisible|adjustResize"
 . . . 
>

 

Values set here (other than "stateUnspecified " and "adjustUnspecified ") override values set in the theme.

 

Value Description
"stateUnspecified " The state of the soft keyboard (whether it is hidden or visible) is not specified. The system will choose an appropriate state or rely on the setting in the theme.

This is the default setting for the behavior of the soft keyboard.

"stateUnchanged " The soft keyboard is kept in whatever state it was last in, whether visible or hidden, when the activity comes to the fore.
"stateHidden " The soft keyboard is hidden when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
"stateAlwaysHidden " The soft keyboard is always hidden when the activity's main window has input focus.
"stateVisible " The soft keyboard is visible when that's normally appropriate (when the user is navigating forward to the activity's main window).
"stateAlwaysVisible " The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
"adjustUnspecified " It is unspecified whether the activity's main window resizes to make room for the soft keyboard, or whether the contents of the window pan to make the currentfocus visible on-screen. The system will automatically select one of these modes depending on whether the content of the window has any layout views that can scroll their contents. If there is such a view, the window will be resized, on the assumption that scrolling can make all of the window's contents visible within a smaller area.

This is the default setting for the behavior of the main window.

"adjustResize " The activity's main window is always resized to make room for the soft keyboard on screen.
"adjustPan " The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

 

 

分享到:
评论

相关推荐

    android安卓app已经放弃使用Theme.Dialog,改用Theme.Holo.DialogWhenLarge

    至于附件中的"旧版Theme.Dialog.png"和"新版Theme.Holo.DialogWhenLarge.png",它们很可能是用来比较两种主题在实际应用中的视觉效果。通过图片对比,开发者可以直观地看到更改主题后的界面差异,帮助他们评估并确认...

    完美实现将activity作为dialog弹窗进行弹出

    添加`android:theme`属性,设置为`Theme.AppCompat.Dialog`或`Theme.Material3.DayNight.Dialog`(根据你的项目所使用的主题风格选择)。例如: ```xml &lt;activity android:name=".YourActivity" android:theme="@...

    Android Dialog更改样式及显示位置

    1. 自定义对话框布局:创建一个自定义的Dialog布局文件,然后在代码中动态设置对话框的宽高,以达到改变位置的效果。例如: ```java Dialog dialog = new Dialog(context, R.style.CustomDialogTheme); dialog....

    jQuery.dialog.js网页弹出对话框美化特效插件

    jQuery.dialog.js是一个专为网页开发者设计的轻量级插件,旨在提供美观且功能丰富的对话框效果。该插件以其简洁的API和多样化的样式选择,使得对话框的创建变得简单易行,极大地提升了用户体验。 首先,jQuery....

    jquery.dialogBox.js动画对话框插件

    《jQuery.dialogBox.js动画对话框插件详解及应用实践》 在网页开发中,对话框是一种常见的用户交互元素,用于提示信息、确认操作或者展示详细内容。jQuery.dialogBox.js插件是一个轻量级且功能丰富的动画对话框工具...

    Android使用Activity用作弹出式对话框

    在`res/values/styles.xml`文件中,我们可以定义一个新的主题,例如`Theme.AppCompat.Dialog.Alert`,它会使`Activity`呈现为对话框样式。 ```xml &lt;style name="PopupTheme" parent="Theme.AppCompat.Dialog.Alert...

    jquery.dialog.js 经典弹出框附案例代码

    `jQuery.dialog.js`是基于jQuery库的一个经典弹出框插件,它为网页开发者提供了方便、灵活的对话框功能。这个插件使得在网页中创建模态或非模态的对话框变得轻而易举,无需复杂的HTML和CSS布局,大大简化了前端交互...

    自定义Dialog(Activity样式改为Dialog)

    setContentView(R.layout.activity_my_custom_dialog); // 获取布局中的控件 TextView title = findViewById(R.id.dialog_title); TextView content = findViewById(R.id.dialog_content); Button okButton = ...

    Android Dialog风格的Activity

    setContentView(R.layout.activity_dialog); Button btnCancel = findViewById(R.id.button_cancel); btnCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ...

    DialogActivity

    - 在AndroidManifest.xml中声明一个新的`Activity`,并设置主题为`Theme.AppCompat.Dialog`或`Theme.MaterialComponents.Dialog`。这将使`Activity`以对话框样式呈现。 ```xml &lt;activity android:name=".Dialog...

    Android中dialog常用样式

    &lt;style name="CustomDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert"&gt; &lt;item name="android:windowBackground"&gt;@color/your_color &lt;item name="colorAccent"&gt;@color/your_accent_color ``` 在`...

    art.dialog

    "art.dialog"是一款高效、轻量级的弹窗插件,专为简化网页中的弹出对话框实现而设计。这款插件的特点在于它无需预先加载文件,能够在需要时快速响应,提供灵活、自定义化的用户体验,同时保持了代码的简洁和易用性。...

    Dialog样式的Activity-可以在任何地方弹出的Dialog

    setContentView(R.layout.activity_dialog); Button closeButton = findViewById(R.id.btnClose); closeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ...

    Android中使用Dialog风格弹出框的Activity

    setContentView(R.layout.activity_dialog); Button positiveButton = findViewById(R.id.dialog_positive_button); Button negativeButton = findViewById(R.id.dialog_negative_button); positiveButton....

    activity dialog

    为了进一步学习,你可以查看这个项目的源代码,包括布局文件(如activity_dialog.xml)、Activity类(如YourDialogActivity.java)以及可能的主题样式文件(res/values/styles.xml)。 总之,"activity dialog"是...

    jquery.dialog插件参数说明

    当`bgiframe`设置为`true`时,对话框下方会插入一个背景iframe,用于解决在Internet Explorer浏览器中,弹窗无法覆盖下拉菜单或`&lt;select&gt;`元素的问题。启用方式如下: ``` $(".class").dialog({bgiframe:true}); ```...

    dialog效果的activity

    在Android开发中,`dialog效果的activity`是一种常见的设计模式,它允许开发者将对话框(Dialog)的功能集成到一个独立的Activity中,从而实现更好的代码复用和模块化。这样的设计能够将对话框的逻辑与主Activity的...

    jquery ui中的dialog

    标签中的"源码"可能指的是获取和理解jQuery UI Dialog的内部工作原理,而"工具"可能是指使用在线代码编辑器或调试工具进行开发和测试。 以上就是关于jQuery UI中Dialog组件的主要知识点。掌握这些内容后,开发者...

    jquery.ui.dialog

    里面是经过修改的jquery.ui.dialog.js(版本jQuery UI Dialog 1.8.12),添加了parentElement: 'body',详情查看http://forum.jquery.com/topic/dialog-will-move-its-div-tag-to-body

    Android 悬浮Activity ( Dialog风格)

    在Android中实现悬浮Activity,首先需要创建一个新的Activity,并在布局文件中设置其样式为Dialog样式。这可以通过修改`&lt;style&gt;`标签中的`parent`属性为`Theme.AppCompat.Dialog`来实现。同时,为了使Activity浮现在...

Global site tag (gtag.js) - Google Analytics