我需要做一个非常简单的事情 - 找出是否显示了软件键盘.这在Android中可行吗?
我在新的Android KitKat(4.4)中使用半透明操作栏/导航栏时出现问题windowSoftInputMode="adjustResize".
Normaly将InputMode更改为adjustResize,应用程序应该在键盘显示时自行调整大小......但是在这里它不会!如果我删除透明效果的行,则调整大小正常.
因此,如果键盘可见,我的ListView就在它下面,我无法访问最后几个项目.(只能手动隐藏键盘)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="XYZ"
android:versionCode="23"
android:versionName="0.1" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.XYZStyle" >
<activity
android:name="XYZ"
android:label="@string/app_name"
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)
值-V19/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.XYZStyle" parent="@style/Theme.AppCompat.Light">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
fragment.xml之
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listView_contacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="@null"
android:dividerHeight="0dp"
android:drawSelectorOnTop="true"
android:fastScrollAlwaysVisible="true"
android:fastScrollEnabled="true"
android:paddingBottom="@dimen/navigationbar__height" >
</ListView> …Run Code Online (Sandbox Code Playgroud) android resize statusbar window-soft-input-mode android-4.4-kitkat
有问题谈论这个问题,但我没有通过现有的答案解决我的问题.
这是我的styles-v21.xml:
<style name="MainTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:colorBackground">#EEEEEE</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我当然为相关的Activity设置了windowSoftInputMethod ="adjustResize".
这是我的layout.xml,注意根FrameLayout用于特定功能,因此需要它:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/rl_background"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--This View is used to fill the space of status bar-->
<View
android:id="@+id/statusbar"
android:layout_width="match_parent"
android:layout_height="@dimen/statusbar_size"/>
<!--I've set this toolbar as Actionbar-->
<android.support.v7.widget.Toolbar
android:id="@+id/actionbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="@id/statusbar"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/actionbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Two EditTexts inside -->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)
当我没有触摸EditText时,一切看起来都很好:状态栏View保持原样,导航栏不覆盖内容(不要让内容不可见,但实际上内容不在其中).
在类似的问题中,人们经常教我们设置fitsSystemWindow ="true",我在layout.xml中的不同布局中做了这个,得到了不同的结果.
设置fitsSystemWindow ="true":
1.FrameLayout:AdjustResize有效,但状态栏View现在保持在真实状态栏下方.状态栏的颜色变为windowBackground.导航栏变得完全透明,因为它显示了添加此片段的其他片段内容.
2.First RelativeLayout:AdjustResize有效,但状态栏View低于实际状态栏.导航栏不太透明,无法显示其他片段,但覆盖内容.
ScrollView中的3&4.ScrollView和RelativeLayout:AdjustResize不起作用,其他条件与条件2相同.
我还使用了一种方法来编写我自己的FrameLayout,如下所示:https://stackoverflow.com/a/22266717/3952691 但正如作者所说,设置底部会导致错误.因为我使用半透明导航栏,我还需要绘制底部插图.我尝试升级版本:https …
我在我的Android应用程序中有以下布局但我windowSoftInputMode="adjustResize"在活动中遇到问题:名为"容器"的LinearLayout包含多个EditTexts但当其中一个有焦点并且键盘出现时,Activity不会调整大小并且EditText隐藏在键盘后面.我认为这与它有关,CoordinatorLayout但我无法弄清楚它有什么问题.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="#F0f0f0">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll"
app:contentScrim="?attr/colorPrimary">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="parallax"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="?attr/actionBarSize"
android:padding="15dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<EditText
android:id="@+id/titleEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="60"
android:hint="Title"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp">
<EditText
android:id="@+id/descriptionEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="120"
android:hint="Description"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-layout window-soft-input-mode android-coordinatorlayout
我有一个WebView(在带有SlidingTabLayout的ViewPager中的片段内).
使用WebView进行输入时,我希望调整布局以确保输入可见.
单击WebView中的文本输入时,将显示软键盘并调整布局大小.我可以输入我的文本并使用软键盘的返回按钮提交或使用后退按钮取消输入.在此之后,键盘消失,布局调整大小.正确的AdjustResize行为.
但是,当通过在软键盘外部单击来解除键盘时(例如,在Google中输入查询并按下WebView中的"搜索"按钮)键盘会隐藏,并且布局调整大约需要2-3秒(留下空白区域)在我的布局底部2-3秒).之后,在选择textinput时,键盘将覆盖WebView(adjustPan).
如何确保通过按WebView关闭键盘时,adjustResize可以保持行为.
我尝试重新设置AdjustResize(例如来自onTouch),但这没有效果:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
我也尝试过以下解决方案,但这没有任何改变.
此外,我认为这可能不是一个焦点问题(因为键盘确实出现了,webview确实响应).我确实从我的观点中提出焦点:
webView.setFocusable(true);
webView.setFocusableInTouchMode(true);
Run Code Online (Sandbox Code Playgroud) 我有以下布局
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:background="@drawable/background_grey"
android:fillViewport="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="@+id/logo_layout"
android:layout_width="fill_parent"
android:layout_height="@dimen/layout_height"
android:layout_alignParentTop="true"
android:background="@drawable/logo_container" >
<!-- some layout components-->
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/logo_layout"
android:layout_margin="@dimen/default_margin" >
<!-- some layout components-->
<RelativeLayout
android:id="@+id/activation_code_entry_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/activation_body_second_paragraph"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@drawable/enter_passcode_background"
android:gravity="center_vertical" >
<!-- some layout components-->
<EditText
android:id="@+id/activationCode"
style="@style/FormField"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/side_margin"
android:hint="@string/activation_enter_code"
android:inputType="number"
android:maxLength="10"/>
<!-- some layout components-->
</RelativeLayout>
<!-- some layout components-->
</RelativeLayout>
</RelativeLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
在Application Manifest文件中,我将活动设置为
<activity
android:name=".activities.MyActivity"
android:enabled="true" …Run Code Online (Sandbox Code Playgroud)