How to add margin between EditText and Soft Keyboard?

前端 未结 6 1718
刺人心
刺人心 2020-12-16 09:58

I want to add 10dp margin between EditText and Soft Keyboard.

\"enter Here is my XML:<

相关标签:
6条回答
  • 2020-12-16 10:11

    The Vasily Kabunov answer works for me but his answer need a little change for working. The next code is:

    editTextField.setOnFocusChangeListener(new OnFocusChangeListener() {
    
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // TODO Auto-generated method stub
            if (hasFocus) {
                    Handler(Looper.getMainLooper()).postDelayed({
                        //Take care with this line I think that the scroll moves in px and not with dp.
                        scrollView.scrollBy(0, 80)
                    }, 100) //You need to play with the time if your activity comes from onCreate and onResume you need to change this value to 1000.
                }
    
        });
    }
    

    And you need to add in your ScrollView or RecyclerView the next lines:

    android:paddingBottom="80dp"
    android:clipToPadding="false"
    

    IMPORTANT: If you have activated fullscreen the flags adjustResize and adjustPan don't work.

    0 讨论(0)
  • 2020-12-16 10:13

    Try to add your RelativeLayout in ScrollView, and then add code below:

    editTextField.setOnFocusChangeListener(new OnFocusChangeListener() {
    
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            // TODO Auto-generated method stub
            if (hasFocus)
                 scrollView.scrollBy(0, 150);
    
        });
    
    0 讨论(0)
  • 2020-12-16 10:20

    I find the attribute of paddingBottom can effect the distance between the editText and the keyboard. You can do like this:

    <RelativeLayout   
      android:layout_width="match_parent"   
      android:layout_height="110dp"> 
      <ImageView
         android:layout_width="match_parent"
         android:layout_height="100dp"
         android:background="@drawable/your_edit_text_background"/>   
      <EditText
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:paddingBottom="10dp"/> 
    </RelativeLayout>
    

    This will make your keyboard margin your EditText by 10dp

    0 讨论(0)
  • 2020-12-16 10:20

    Adding android:windowSoftInputMode="adjustResize" to the activity in manifest should solve the issue. And this won't work if your activity is running in fullscreen. So in that case, instead of making it fullscreen via code, just add or change the style <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> to style.xml and use this as your AppTheme. adjustResize or adjustPan both will work.

    0 讨论(0)
  • 2020-12-16 10:25

    This seems to work, though has some unwanted effect on the layout.

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

    If anybody knows how to get this working with ADJUST_PAN, that would be great!

    0 讨论(0)
  • 2020-12-16 10:26

    I solved the same problem by adding just two lines

    Add this line in EditText -

    android:imeOptions="actionSend|flagNoEnterAction"
    

    and this line in Manifeast file in Activity tag add -

    <activity
                android:name="----"
                android:icon="---"
                android:windowSoftInputMode="stateVisible|adjustResize"
                android:label="@string/app_name"
                android:theme="-----" />
    

    and remove all code that you use to do this like onTouchListner and it should work.

    0 讨论(0)
提交回复
热议问题