The previous Android immersive status bar implementation did not take into account the impact of the soft keyboard, the next content will be to solve the problem, first look at
This is a message board:
That is, when the soft keyboard is ejected, it does not cause the entire layout to move up.
How to do it in detail? Follow the steps below to set it up:
1, the layout file declaration such as the following
<activity android:name= "com.storm.durian.activity.LeaveMessageDetailsActivity" android: screenorientation= "Portrait" />
2, here rewrite the relativelayout. And Fitsystemwindows, this is the most important.
/** * Adaptive Layout */public class Fitssystemwindowslayout extends Relativelayout {private static final String TAG = Fitssyste MWindowsLayout.class.getSimpleName (); Private Softkeyboardstatelistener Softkeyboardstatelistener; Public Fitssystemwindowslayout (Context context) {super (context); } public Fitssystemwindowslayout (context context, AttributeSet Attrs) {Super (context, attrs); } public Fitssystemwindowslayout (context context, AttributeSet attrs, int defstyle) {Super (context, Attrs, DefS Tyle); } @Override protected void onmeasure (final int widthmeasurespec, final int heightmeasurespec) {Dispatchliste Nerlow (HEIGHTMEASURESPEC); Super.onmeasure (Widthmeasurespec, Heightmeasurespec); }/** * Processing low version number keyboard Popup * * @param heightmeasurespec height */private void dispatchlistenerlow (int heightmea SURESPEC) {if (Softkeyboardstatelistener = = NULL | | Build.VERSION.SDK_INT >= build.version_codes. KITKAT) { Return } int oldspec = Getmeasuredheight (); if (oldspec <= 0) {return; } int newspec = Measurespec.getsize (Heightmeasurespec); int offset = Oldspec-newspec; if (offset >) {loghelper.i (TAG, "keyboard Open"); Softkeyboardstatelistener.onsoftkeyboardstatechange (TRUE); } else if (offset < -100) {loghelper.i (TAG, "keyboard off"); Softkeyboardstatelistener.onsoftkeyboardstatechange (FALSE); }} @Override protected Boolean fitsystemwindows (Rect insets) {dispatchlistener (insets); insets.top = 0; Return Super.fitsystemwindows (insets); /** * Distribute Listening * * @param insets */private void Dispatchlistener (Rect insets) {if (Softkeyboa Rdstatelistener = = NULL | | Android.os.Build.VERSION.SDK_INT < Build.version_codes. KITKAT) {return; } if (Insets.top! = 0 && Insets.bottom! = 0) { LOGHELPER.I (TAG, "keyboard Open"); Softkeyboardstatelistener.onsoftkeyboardstatechange (TRUE); } else {loghelper.i (TAG, "keyboard off"); Softkeyboardstatelistener.onsoftkeyboardstatechange (FALSE); }}/** * Set soft keyboard Listener event * * @param softkeyboardstatelistener */public void Setsoftkeyboardlistener (S Oftkeyboardstatelistener softkeyboardstatelistener) {this.softkeyboardstatelistener = SoftKeyBoardStateListener; } public interface Softkeyboardstatelistener {public void Onsoftkeyboardstatechange (Boolean isOpen); }}
Although the above layout also provides the keyboard to open or close the callback, but in some of the lower version of the phone support is not very good, the need for this callback to be able to use this callback as one of the methods. But don't be overly dependent.
3. layout file
Wrap the entire layout with com.storm.durian.view.FitsSystemWindowsLayout and set android:fitssystemwindows= "true"
<?xml version= "1.0" encoding= "Utf-8"?><com.storm.durian.view.fitssystemwindowslayout android:id= "@+id/leave_message_layout" Xmlns:android= "Http://schemas.android.com/apk/res/android" Android:layout_width= "Match_parent" android:layout_height= "Match_parent" android:background= "@color/ececec" Android:fitssystemwindows= "true" > <include android:id= "@+id/leave_message_title" layout= "@layout/ Common_back "/> <linearlayout android:id=" @+id/ll_leave_message_input "android:layout_width=" match_p Arent "android:layout_height=" Wrap_content "android:layout_alignparentbottom=" true "Android:backgroun d= "@drawable/leave_message_bottom_bg" android:orientation= "horizontal" > <edittext android:i D= "@+id/et_leave_message"Android:layout_width=" 0DP "android:layout_height=" Wrap_content "android:layout_weight=" 3 "android:background=" @drawable/et_leave_message_bg "android:hint=" pro, leave me a message I will reply you ~ "Androi D:maxlines= "4" android:textcolor= "@color/_3e363d" android:textsize= "@dimen/text_size_small"/> <button android:id= "@+id/btn_leave_message_send" android:layout_width= "0DP" Androi d:layout_height= "Wrap_content" android:layout_marginleft= "10DP" android:layout_weight= "1" android:background= "@drawable/btn_leave_message_send_selector" android:singleline= "true" Android:te xt= "Send" android:textcolor= "@color/_3e363d" android:textsize= "@dimen/text_size_middle"/> </l inearlayout> <listview android:id= "@+id/lv_leave_message" android:layout_width= "Match_parent" android:layout_height="Wrap_content" android:layout_above= "@id/ll_leave_message_input" android:layout_below= "@id/leave_message_tit Le "android:cachecolorhint=" #00000000 "android:divider=" @color/dbdbdb "android:dividerheight=" 1DP " Android:fadingedge= "None"/> <viewstub android:id= "@+id/activity_leave_message_loading_stub" an Droid:layout_width= "Match_parent" android:layout_height= "match_parent" android:layout_below= "@id/leave_messa Ge_title "android:inflatedid=" @+id/activity_leave_message_loading_subtree "android:layout=" @layout/common_lo Ading "/> <viewstub android:id=" @+id/leave_message_empty_stub "android:layout_width=" Match_parent " android:layout_height= "Match_parent" android:layout_above= "@id/ll_leave_message_input" Android:layout_ below= "@id/leave_message_title" android:inflatedid= "@+id/leave_message_empty_subtree" android:layout= "@layou T/common_tips_layout "/> <viewstub android:id= "@+id/leave_message_net_error_stub" android:layout_width= "Match_parent" Andro id:layout_height= "Match_parent" android:layout_below= "@id/leave_message_title" android:inflatedid= "@+id/leav E_message_net_error_subtree "android:layout=" @layout/common_net_error_layout "/></ Com.storm.durian.view.fitssystemwindowslayout>
4. Handling in activity
Set Setimmerselayout (Findviewbyid (r.id.leave_message_title));
@Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_leave_detail_message); Setimmerselayout (Findviewbyid (R.id.leave_message_title)); Logic = Leavemessagelogic.getinstance (Getapplicationcontext ()); Mhandler = new MyHandler (this); Initview (); }
Another look at the Setimmerselayout method in Baseactivity
The version number is still above 4.4.
@Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (SA Vedinstancestate); Isstart = true; SHARESDK.INITSDK (this); if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {//Transparent status bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); Transparent navigation bar//GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); Statusbarheight = Screenutil.getstatusbarheight (this); } screenmanager.getscreenmanager (). pushactivity (this); }
protected void Setimmerselayout (view view) { if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) { window window = GetWindow (); Window.setflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_ Translucent_status); Window.addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); int statusbarheight = Screenutil.getstatusbarheight (This.getbasecontext ()); View.setpadding (0, statusbarheight, 0, 0); } }
Ok. Friends who need to be able to try it on their own!
If you are free, you will be sharing the function of this immersive message board!
Android Immersive status bar implementation (bottom)