簡體   English   中英

Android軟鍵盤隱藏控件

[英]Android soft keyboard hides controls

我知道對此有很多疑問,但是沒有一個答案對我有用。 在打開鍵盤之前,這是一個有問題的屏幕。

在此處輸入圖片說明

這是通過點擊EditText,然后盡可能向下滾動來打開鍵盤之后的屏幕。

在此處輸入圖片說明

請注意,除了最終的編輯控件大部分被隱藏之外,所有文本和其后的按鈕均不可訪問。

這是片段布局:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:validator="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity$PlaceholderFragment"
        android:background="@color/background">

        <TextView android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/primary"
            android:text="@string/help_header"
            android:textSize="20sp"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            />

        <TextView android:id="@+id/drop"
            android:layout_below="@id/header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/help_sub_header"
            android:textSize="16sp"
            android:textColor="@color/material_drawer_secondary_text"
            android:layout_marginLeft="@dimen/activity_horizontal_margin"
            android:layout_marginRight="@dimen/activity_horizontal_margin"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            />

        <View android:id="@+id/divider1"
            android:layout_below="@id/drop"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@color/light_gray_background"
            android:layout_marginBottom="@dimen/activity_vertical_margin"/>

        <LinearLayout android:id="@+id/linear1"
            android:layout_below="@id/divider1"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin">

            <!-- Several EditTexts and such -->

        </LinearLayout>
    </RelativeLayout>
</ScrollView>

它最初是在LinearLayout中,我根據一個建議將其更改為RelativeLayout,但是並沒有任何改變。 我也一直在使用視圖組的前兩個級別的布局高度(wrap_content / match_parent),但沒有任何效果。 這是清單中的活動聲明:

<activity
            android:name=".MainActivity"
            android:label="@string/application_name"
            android:windowSoftInputMode="adjustResize" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>

我也嘗試過AdjustPan,它似乎並沒有改變。 我不太擔心打開鍵盤時UI元素的確切作用,我只是希望通過滾動即可訪問整個布局。

基本上每個人都指向軟輸入模式,但這似乎無濟於事。 我缺少一些有關碎片的信息嗎? 還是這比我預期的難,我需要制作一個自定義的布局類並測量布局和類似的東西嗎? 我可以添加活動布局,盡管沒有太多內容,也可以添加諸如片段創建/事務之類的代碼。

這就是鍵盤的作用。 它覆蓋了屏幕的底部。 如果您不希望它完全覆蓋您的應用程序,則可以使用adjustResize。 這樣可以擴展您的應用,使其只吸引上半部分。 但是,如果您的內容太大,它仍然無法容納,並且看起來好像您的應用程序已被覆蓋(即使它沒有覆蓋。那么通過滾動視圖滾動它就可以了(盡管我從未真正嘗試過))但是,當鍵盤彈起時,您唯一可以控制行為的方法是softInputMode。

如果您有大量可調整的空間或空白,那么有些技術會使您有所縮小,並可能使完整的應用程序顯示在縮小的空間中。 此處不是這種情況,您的屏幕上有太多東西(也許在縱向模式下的平板電腦上除外)。 所以他們不會在這里申請。

原來問題出在一個庫,材質抽屜(漂亮的庫)。 對於其他遇到此問題的人:

https://github.com/mikepenz/MaterialDrawer/blob/master/README.md#i-have-problems-with-the-softkeyboard-how-can-i-fix-this

調用Drawer.keyboardSupportEnabled(this,true) ,布局將適當安排和滾動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM