簡體   English   中英

編輯EditText時工具欄會調整到til軟鍵盤的大小

[英]Toolbar resizes til softkeyboard when editing EditText

這是我的第一個問題,經過2個小時的搜索,我找不到與此相關的案例。

問題是我有一個帶有工具欄(v7支持工具欄)和導航抽屜的活動。 所有這一切都完美。 主要活動有一個片段容器,我在其中放置了不同的片段(通過導航抽屜)。 一切正常,直到我向片段添加了EditText。 當我選擇EditText輸入一些文本時,將顯示軟鍵盤,並且工具欄將調整大小,直到底部與軟鍵盤對齊(實際高度增加)為止,我還不能發布圖像,所以我希望它足夠詳細。 未選擇輸入的片段將正常顯示。 EditText實際上位於softKeyboard的下面(至少可以在此處看到選擇指示器)。

這是來自mainactivity的布局文件:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" android:background="@color/main_color_500"> <android.support.v4.widget.DrawerLayout android:id="@+id/drawer_layout" android:layout_height="match_parent" android:layout_width="match_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="0dp" android:paddingRight="0dp" android:paddingTop="0dp" android:paddingBottom="0dp" android:orientation="vertical" tools:context="com.joost.smartplanner.MainFragmentActivity"> <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/main_color_500" android:fitsSystemWindows="true" android:elevation="4dp" android:id="@id/app_bar" app:theme="@style/CustomToolbarStyle"> </android.support.v7.widget.Toolbar> <FrameLayout android:id="@+id/mainFragmentContainer" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:background="@color/grey_100" android:padding="@dimen/zero_padding" android:gravity="top" android:orientation="horizontal" android:focusable="true"> </FrameLayout> </LinearLayout> <fragment android:id="@+id/fragment_navigation_drawer" android:layout_width="@dimen/nav_drawer_width" android:layout_height="match_parent" android:layout_gravity="start" app:layout="@layout/fragment_navigation_drawer" android:name="com.joost.smartplanner.NavigationDrawerFragment" /> </android.support.v4.widget.DrawerLayout> </LinearLayout> 

包含editText的片段:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/fragment_bg_white" android:focusable="true" tools:context="com.joost.smartplanner.CreateEventFragment"> <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/create_event_scrollview"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/divider" android:layout_marginTop="8dp" android:layout_marginBottom="8dp"/> <!-- Event name part --> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="text" android:imeOptions="flagNoExtractUi" android:hint="Event name" android:padding="8dp" android:ems="8" android:focusable="true" android:clickable="true" android:id="@+id/editText" /> </LinearLayout> </ScrollView> </LinearLayout> 

最后,MainActivity onCreate中的工具欄啟動代碼:

 //Toolbar initiation toolbar = (Toolbar) findViewById(R.id.app_bar); setSupportActionBar(toolbar); toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp); getSupportActionBar().setTitle(""); getSupportActionBar().setDisplayHomeAsUpEnabled(true); toolbar.setNavigationOnClickListener(new View.OnClickListener(){ @Override public void onClick(View view) { } }); toolbar.inflateMenu(R.menu.menu_main); 

我試圖消除此問題的一件事是為工具欄設置了固定高度,而不是wrap_content值。 這部分解決了工具欄保持相同高度但工具欄內的圖標消失的問題,並且我認為硬編碼通常可以正常工作的高度不是正確的解決方案。

您在此處看到的問題與工具欄中的android:fitSystemWindows="true"屬性有關。

看一下searchview成為焦點時Android appcompat工具欄的伸展情況 看來,如果您使用該屬性,則父視圖也應該設置android:fitSystemWindows="true"

暫無
暫無

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

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