In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to deal with the Android input method pop-up window bug, I hope you will gain something after reading this article, let's discuss it together!
Preface
Recently found a bug, in a project interface, whenever the input method pops up, the background always moves up with the input method, resulting in the background being compressed. Although it doesn't matter, it is extremely unpleasant to find this bug.
Other people's product handling
I took a mobile phone as an example.
The search box should be at the top so that even if the input method pops up, it will not be obscured.
Nuggets comments similar input box at the bottom, input content, the input box follows the input method up, the background does not move
Wechat chat interface, the background does not move, the input box and chat record move up with the input method
These three scenarios basically cover most scenarios that contain input boxes, so let's see how to implement them next.
Realize
The code at the top of the input box will not be mentioned.
Realization of input frame pop-up window of Nuggets
You can easily see that the Nuggets pop-up window is more complex, but also can insert pictures and expressions.
And after the pop-up window comes out, the original article is not allowed to slide.
From this, it can be concluded that the pop-up window of the Nuggets comment is a Dialog and the Activity of the Dialog theme.
Then let's check it out.
Is it right that the Activity of this pop-up window is called TransparentCommentActivityNew?
Is it right that the Activity for details of the article is called DetailActivity?
@ Nuggets Android developer
This is very simple, when the emergence of a new Activity, there is no need to consider the original Activity background compression, layout adaptation.
Because everything is done in the new Activity, and you can't operate the Activity below.
Summary: a new pop-up theme Activity can simply and conveniently solve the problem of layout disorder caused by input method.
The problem that weChat chat background will not be compressed.
I have a problem that has been solved for a long time. Is the normal layout, the background will be compressed by the input method.
Look at the code:
Effect picture (you can see that the moon is compressed):
Solution method
Method one
The Activity configuration in the AndroidManifest.xml file:
Android:windowSoftInputMode= "adjustResize | stateHidden"
Set the background in the onCreate method instead of the background in xml:
GetWindow () setBackgroundDrawableResource (R.mipmap.test)
Method two
The Activity configuration in the AndroidManifest.xml file:
Android:windowSoftInputMode= "adjustResize | stateHidden"
two。 Layout files set custom background
Public class MyBackground extends RelativeLayout {private Context mContext; public MyBackground (Context context) {super (context); mContext = context;} public MyBackground (Context context, AttributeSet attrs) {super (context, attrs); mContext = context;} public MyBackground (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); mContext = context } public MyBackground (Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {super (context, attrs, defStyleAttr, defStyleRes); mContext = context;} @ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {DisplayMetrics dm = new DisplayMetrics (); WindowManager mWm = (WindowManager) mContext.getSystemService (Context.WINDOW_SERVICE); mWm.getDefaultDisplay (). GetMetrics (dm); int screenHeight = dm.heightPixels HeightMeasureSpec = MeasureSpec.makeMeasureSpec (screenHeight, MeasureSpec.EXACTLY); super.onMeasure (widthMeasureSpec, heightMeasureSpec);}} method 3
The Activity configuration in the AndroidManifest.xml file:
Android:windowSoftInputMode= "adjustNothing | stateHidden"
Dynamically calculate the height of the input box, add an equal height View below the EditText when the input method pop-up window, and disappear the View when the input method disappears.
After reading this article, I believe you have a certain understanding of "how to deal with Android input method pop-up bug". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.