EditText input content is not displayed

The normal display effect should be like this:

The system displays abnormalities in 9.0, and the symptoms are as follows:

Problem recurrence

It can be seen that the two input boxes above are displayed in real time when entering characters. When the cursor moves to the bottom input box, the cursor stops beating, and the input characters will not be displayed in real time. When the keyboard is retracted At that time the characters appeared again.

First, there are two solutions:

The first: set android:windowSoftInputMode to "adjustResize|stateHidden" (not recommended)

 

android:windowSoftInputMode="adjustResize|stateHidden" 
 

 

 
  1. <application

  2. ...

  3. android:hardwareAccelerated= "false"

  4. android:theme= "@style/Theme.AppCompat.Light.NoActionBar">

  5.  
  6. <activity

  7. android:name= ".activity.LoginActivity"

  8. ...

  9. android:windowSoftInputMode= "adjustUnspecified|stateHidden" />

  10. </application>

The second: turn on hardware acceleration

After my various tests, I found that the problem is caused by the fact that the hardware acceleration is not turned on.

(WTF, there will be problems when hardware acceleration is turned on, and there will be problems if there is no meeting in 9.0, WTF )

1. Turn on hardware acceleration under application (needless to say, it is not recommended, but it does work well)

 
  1. <application

  2. ...

  3. android:hardwareAccelerated= "false"

  4. android:theme= "@style/Theme.AppCompat.Light.NoActionBar">

  5.  
  6. <activity

  7. android:name= ".activity.LoginActivity"

  8. ...

  9. android:windowSoftInputMode= "adjustUnspecified|stateHidden" />

  10. </application>

2. Turn on hardware acceleration under the activity node (yes, recommended)

 
  1. <application

  2. ...

  3. android:hardwareAccelerated= "false"

  4. android:theme= "@style/Theme.AppCompat.Light.NoActionBar">

  5.  
  6. <activity

  7. android:name= ".activity.LoginActivity"

  8. ...

  9. android:hardwareAccelerated= "true"

  10. android:windowSoftInputMode= "adjustUnspecified|stateHidden" />

  11. </application>

3. Enable hardware acceleration for the specified view (strongly recommended)

        EidtText.setLayerType(View.LAYER_TYPE_HARDWARE,null);
 

Please choose one of the above three according to your needs

 

 

analyse problem:

(I didn't find the right direction at the beginning, and took some detours. The writing below is more verbose, you can skip the ones you don't like)

The original layout file is as follows:

 
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

  2. android:layout_width= "match_parent"

  3. android:layout_height= "match_parent"

  4. android:layout_centerInParent= "true"

  5. android:layout_centerHorizontal= "true"

  6. android:layout_centerVertical= "true"

  7. android:paddingLeft= "40dp"

  8. android:paddingRight= "40dp"

  9. android:background= "@color/white_color"

  10. android:focusable= "true"

  11.  
  12. android:focusableInTouchMode= "true"

  13. android:gravity= "center"

  14. android:orientation= "vertical">

  15.  
  16. <ImageView

  17. android:layout_width= "96dp"

  18. android:layout_height= "94dp"

  19. android:background= "#99666666" />

  20.  
  21. <TextView

  22. android:layout_width= "wrap_content"

  23. android:layout_height= "wrap_content"

  24. android:layout_marginTop= "5dp"

  25. android:text= "@string/app_name"

  26. android:textColor= "#585858"

  27. android:textSize= "20sp"

  28. android:visibility= "invisible" />

  29.  
  30. <LinearLayout

  31. android:layout_width= "match_parent"

  32. android:layout_height= "wrap_content"

  33. android:layout_marginTop= "25dp"

  34. android:orientation= "vertical">

  35.  
  36. <TextView

  37. android:layout_width= "wrap_content"

  38. android:layout_height= "wrap_content"

  39. android:layout_marginLeft= "5dp"

  40. android:layout_marginBottom= "5dp"

  41. android:text= "Enterprise ID:"

  42. android:textSize= "14sp" />

  43.  
  44. <ImageView

  45. android:id= "@+id/iv_company"

  46. android:layout_width= "40dp"

  47. android:layout_height= "40dp"

  48. android:padding= "4dp"

  49. android:scaleType= "fitXY"

  50. android:src= "@drawable/ic_title_home_default"

  51. android:visibility= "gone" />

  52.  
  53. <EditText

  54. android:id= "@+id/et_company_login"

  55. android:layout_width= "match_parent"

  56. android:layout_height= "match_parent"

  57. android:layout_marginLeft= "5dp"

  58. android:background= "@drawable/selector_login_edittext"

  59. android:hint= "Please enter the company number"

  60. android:imeOptions= "actionNext"

  61. android:lines= "1"

  62. android:padding= "10dp"

  63. android:paddingLeft= "5dp"

  64. android:singleLine= "true"

  65. android:textColor= "#585858"

  66. android:textSize= "14sp" />

  67. </LinearLayout>

  68.  
  69. <View

  70. android:id= "@+id/view_userfocus_login"

  71. android:layout_width= "match_parent"

  72. android:layout_height= "1dp"

  73. android:background= "@color/white_color" />

  74.  
  75. <LinearLayout

  76. android:layout_width= "match_parent"

  77. android:layout_height= "wrap_content"

  78. android:layout_marginTop= "10dp"

  79. android:orientation= "vertical">

  80.  
  81. <ImageView

  82. android:id= "@+id/iv_user_login"

  83. android:layout_width= "40dp"

  84. android:layout_height= "40dp"

  85. android:padding= "4dp"

  86. android:scaleType= "fitXY"

  87. android:src= "@drawable/user_white"

  88. android:visibility= "gone" />

  89.  
  90. <TextView

  91. android:layout_width= "wrap_content"

  92. android:layout_height= "wrap_content"

  93. android:layout_marginLeft= "5dp"

  94. android:layout_marginBottom= "5dp"

  95. android:text= "Username:"

  96. android:textSize= "14sp" />

  97.  
  98. <EditText

  99. android:id= "@+id/et_user_login"

  100. android:layout_width= "match_parent"

  101. android:layout_height= "match_parent"

  102. android:layout_marginLeft= "5dp"

  103. android:background= "@drawable/selector_login_edittext"

  104. android:hint= "Username"

  105. android:imeOptions= "actionNext"

  106. android:lines= "1"

  107. android:padding= "10dp"

  108. android:paddingLeft= "5dp"

  109. android:singleLine= "true"

  110. android:textColor= "#585858"

  111. android:textSize= "14sp" />

  112. </LinearLayout>

  113.  
  114. <View

  115. android:layout_width= "match_parent"

  116. android:layout_height= "1dp"

  117. android:background= "@color/white_color" />

  118.  
  119. <LinearLayout

  120. android:layout_width= "match_parent"

  121. android:layout_height= "wrap_content"

  122. android:layout_marginTop= "10dp"

  123. android:orientation= "vertical">

  124.  
  125. <ImageView

  126. android:id= "@+id/iv_password_login"

  127. android:layout_width= "40dp"

  128. android:layout_height= "40dp"

  129. android:padding= "4dp"

  130. android:scaleType= "fitXY"

  131. android:src= "@drawable/password_white"

  132. android:visibility= "gone" />

  133.  
  134. <TextView

  135. android:layout_width= "wrap_content"

  136. android:layout_height= "wrap_content"

  137. android:layout_marginLeft= "5dp"

  138. android:layout_marginBottom= "5dp"

  139. android:text= "Password:"

  140. android:textSize= "14sp" />

  141.  
  142. <EditText

  143. android:id= "@+id/et_password_login"

  144. android:layout_width= "match_parent"

  145. android:layout_height= "40dp"

  146. android:layout_marginLeft= "5dp"

  147. android:background= "@drawable/selector_login_edittext"

  148. android:hint= "Password"

  149. android:imeOptions= "actionDone"

  150. android:inputType= "textPassword"

  151. android:lines= "1"

  152. android:padding= "10dp"

  153. android:paddingLeft= "5dp"

  154. android:singleLine= "true"

  155. android:textColor= "#585858"

  156. android:textSize= "14sp" />

  157. </LinearLayout>

  158.  
  159. <View

  160. android:id= "@+id/view_pwdfocus_login"

  161. android:layout_width= "match_parent"

  162. android:layout_height= "1dp"

  163. android:background= "@color/white_color" />

  164.  
  165. <TextView

  166. android:id= "@+id/btn_login"

  167. android:layout_width= "match_parent"

  168. android:layout_height= "wrap_content"

  169. android:layout_marginTop= "30dp"

  170. android:background= "@drawable/selector_greem_btn_bg"

  171. android:gravity= "center"

  172. android:padding= "8dp"

  173. android:text= "Login"

  174. android:textColor= "@color/white_color"

  175. android:textSize= "16sp" />

  176.  
  177. <RelativeLayout

  178. android:layout_width= "match_parent"

  179. android:layout_height= "40dp"

  180. android:layout_marginTop= "15dp">

  181.  
  182. <CheckBox

  183. android:id= "@+id/cb_remember_login"

  184. android:layout_width= "wrap_content"

  185. android:layout_height= "wrap_content"

  186. android:layout_alignParentStart= "true"

  187. android:layout_alignParentLeft= "true"

  188. android:layout_centerVertical= "true"

  189. android:background= "@drawable/selector_remember_login"

  190. android:button= "@null" />

  191.  
  192. <TextView

  193. android:layout_width= "wrap_content"

  194. android:layout_height= "wrap_content"

  195. android:layout_centerVertical= "true"

  196. android:layout_marginLeft= "5dp"

  197. android:layout_toRightOf= "@+id/cb_remember_login"

  198. android:text= "Remember password"

  199. android:textSize= "@dimen/text_moderate_size" />

  200.  
  201. <Button

  202. android:id= "@+id/btn_config_login"

  203. android:layout_width= "80dp"

  204. android:layout_height= "match_parent"

  205. android:layout_alignParentRight= "true"

  206. android:background= "@drawable/login_item_btn"

  207. android:onClick= "onConfig"

  208. android:text= "System Configuration"

  209. android:textColor= "#149048"

  210. android:textSize= "@dimen/text_moderate_size"

  211. android:visibility= "gone" />

  212. </RelativeLayout>

  213. </LinearLayout>

Original manifest file:

 
  1. <activity

  2. android:name= ".activity.LoginActivity"

  3. android:configChanges= "orientation|keyboardHidden|navigation|screenSize"

  4. android:icon= "@drawable/user_btn"

  5. android:launchMode= "singleTask"

  6. android:screenOrientation= "portrait"

  7. android:windowSoftInputMode= "adjustPan|stateHidden" />

同样的代码拷贝到demo里运行没有问题,项目里运行就有问题
 

The manifest file was then simplified as follows:

 
  1. <activity

  2. android:name= ".activity.LoginActivity"

  3. android:windowSoftInputMode= "adjustPan|stateHidden" />

        <activity android:name=".activity.LoginActivity"/>
 
 
  1. <activity

  2. android:name= ".activity.LoginActivity"

  3. android:windowSoftInputMode= "adjustUnspecified|stateHidden" />

The problem was not solved, and then guessed:

1. Is it caused by some code in the java file?

2. Does the keyboard pop-up block the input box?

Verify the first conjecture:

1. Change the position of the user name in the second input box and the password in the third input box in the layout. After running it, it is found that the password input box is normal, and the user name input box has the same problem;

2. Make a copy of the password input box in the layout at the end, remove the id of the control, and after running it, it is found that the above problems have occurred in both password boxes;

3. Change LoginActivity to the following:

 
  1. public class LoginActivity extends Activity {

  2. @Override

  3. protected void onCreate(@Nullable Bundle savedInstanceState) {

  4. super.onCreate (savedInstanceState);

  5. setContentView(R.layout.activity_login);

  6. }

  7. }

Found after running: the problem still exists

Conclusion: The problem has nothing to do with java code

Verify the second conjecture:

Put multiple EditTexts side by side in a LinearLayout in the vertical direction, and wrap a NestedScrollView in the outer layer. After running, a magical phenomenon appears:

When inputting, no characters are displayed, and characters appear in the input box when swiping upwards, and a half pull box is left above the keyboard.

Guess you like

Origin blog.csdn.net/guodashen007/article/details/108768508