ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 软键盘将工具栏推入顶部状态栏

2019-07-02 11:10:46  阅读:174  来源: 互联网

标签:android layout xml toolbar


我已经完成了至少十个类似的SO问题,似乎没有任何效果.

我有一个简单的相对布局,包括工具栏,文本视图,编辑文本等(请参阅下面的xml).

当编辑文本被聚焦时,我需要软键盘向上推动我的布局,但在工具栏下(即工具栏固定),而键盘推动整个布局,包括工具栏?

我已经尝试过adjustPan,adjustResize,scrollviews等没有成功,任何帮助都将不胜感激.

layout xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.Test">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:id="@+id/appbar_layout"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    </android.support.v7.widget.Toolbar>

</android.support.design.widget.AppBarLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/appbar_layout">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent">



        <TextView
            android:id="@+id/tv_title"
            android:textSize="25dp"
            android:textColor="@color/colorPrimaryDark"
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/iv"
            android:layout_alignParentLeft="true" />

        <TextView
            android:id="@+id/tv_date"
            android:textSize="15dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/iv"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/tv_title"/>



        <ImageView
            android:id="@+id/iv"
            android:layout_marginRight="-6dp"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_alignParentRight="true"
            android:maxHeight="150dp"

            />


        <TextView
            android:id="@+id/tv_description"
            android:layout_marginTop="15dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/iv"
            android:layout_centerHorizontal="true"
            android:textSize="15dp"
            android:textColor="@color/colorPrimaryDark"/>

        <RatingBar
            android:id="@+id/rb"
            style="?android:attr/ratingBarStyle"
            android:layout_centerHorizontal="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv_description"
            android:numStars="5" />

        <View
            android:id="@+id/view"
            android:layout_below="@+id/rb"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_height="1dp"
            android:visibility="visible"
            android:background="@color/colorPrimary"/>

        <EditText
            android:id="@+id/et"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:padding="@dimen/activity_horizontal_margin"
            android:layout_below="@+id/view"
            android:gravity="top"
            android:background="@android:color/transparent"
            />

        <Button
            android:id="@+id/btn"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textColor="@color/textColorPrimary"
            android:textSize="20dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:layout_alignParentBottom="true"
            />
    </RelativeLayout>
</ScrollView>

</RelativeLayout>

解决方法:

我在我的片段的onCreateView上使用此代码,它工作正常.

getActivity()getWindow()setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE).;

标签:android,layout,xml,toolbar
来源: https://codeday.me/bug/20190702/1355582.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有