0

When Bottom sheet is open(First image below) and When tab on editText , the keyboard hides the edit text(Second image below) , i want to move keyword below the "ADD" botton of bottomsheet.How to do this?

enter image description here


Image 2:

enter image description here

Fragment

public class CustomExerciseFragment extends BaseCardFragment {
    private View parent_view;
    private RecyclerView recyclerView;
    private AdapterEasyListAnimation mAdapter;
    private LinkedList<DaysDetails> items = new LinkedList<>();
    private int animation_type = ItemAnimation.BOTTOM_UP;
    private DaysDAO daysDAO;
    private ExercisesDAO exercisesDAO;
    private ImageView imageView;
    private   Button buttonBreif;
    //=========Configure this at the beginning=============
    private final  String routineId="1520";
    private final  String legWorkoutImageName="leg_workout_customize";

    private BottomSheetBehavior mBehavior;
    private BottomSheetDialog mBottomSheetDialog;
    private View bottom_sheet;

    public static CustomExerciseFragment newInstance() {
        CustomExerciseFragment fragment = new CustomExerciseFragment();
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_custom_exercise, container, false);
        mCardView = (CardView) root.findViewById(R.id.cardView);
        mCardView.setMaxCardElevation(mCardView.getCardElevation()
                * CardAdapter.MAX_ELEVATION_FACTOR);


 

        bottom_sheet = root.findViewById(R.id.bottom_sheet_add_days);
        mBehavior = BottomSheetBehavior.from(bottom_sheet);
        mBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
 
        ((ExtendedFloatingActionButton) root.findViewById(R.id.extended_fab)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showAddDaysBottomSheetDialog();
            }
        });

        return root;
    }
 
    private void showAddDaysBottomSheetDialog() {
        if (mBehavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
            mBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
        }

        final View view = getLayoutInflater().inflate(R.layout.sheet_add_days, null);

        mBottomSheetDialog = new BottomSheetDialog(getContext());
        mBottomSheetDialog.setContentView(view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBottomSheetDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        mBottomSheetDialog.show();
        mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                mBottomSheetDialog = null;
            }
        });
    }
}

BottomSheetLayout

  <?xml version="1.0" encoding="utf-8"?>
   <LinearLayout 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="match_parent"
    android:background="@android:color/white"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nested_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:scrollbars="vertical"
        android:layout_gravity="bottom"
        android:scrollingCache="true">


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingBottom="@dimen/spacing_middle"
            android:paddingLeft="@dimen/spacing_mlarge"
            android:paddingRight="@dimen/spacing_mlarge"
            android:paddingTop="@dimen/spacing_middle">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/spacing_medium"
                android:orientation="vertical"
                android:padding="@dimen/spacing_medium">

                <EditText
                    style="@style/EditText.Flat.Grey"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/spacing_xmlarge"
                    android:background="@drawable/edit_text_round_bg_outline"
                    android:inputType="text"
                    android:minHeight="@dimen/spacing_xmlarge"
                    android:paddingLeft="@dimen/spacing_large"
                    android:paddingRight="@dimen/spacing_large"
                    android:text="400" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/spacing_middle"
                android:orientation="vertical">

                <Button
                    style="@style/Button.Primary.Borderless"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/btn_rect_black_grey"
                    android:text="ADD"
                    android:textColor="@android:color/white" />

            </LinearLayout>

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>

</LinearLayout>
Dan
  • 2,086
  • 11
  • 71
  • 137
  • This official tutorial may help: https://youtu.be/OfEOYxWVRTM?t=466, just download the source code and find out the implementation of `DialogFragment`. – Sam Chen Mar 06 '21 at 14:14
  • Does this answer your question? [Show entire bottom sheet with EditText above Keyboard](https://stackoverflow.com/questions/48002290/show-entire-bottom-sheet-with-edittext-above-keyboard) – aliraza12636 Mar 06 '21 at 14:15
  • @SamChen you can see the Keyboard is still hidding the bottom sheet in this video you shared https://youtu.be/OfEOYxWVRTM?t=479 – Dan Mar 06 '21 at 14:17
  • @aliraza12636 As per your linked answer, where should i put `setStyle(DialogFragment.STYLE_NORMAL, R.style.DialogStyle)` in my code ? – Dan Mar 06 '21 at 14:20
  • @aliraza12636 I tried to follow your suggested answer but this line is showing error when placing https://i.stack.imgur.com/jnxGM.png – Dan Mar 06 '21 at 14:24
  • So you want the dialog to show completely on top of the soft keyboard? – Sam Chen Mar 06 '21 at 14:38
  • @SamChen Yes you are right – Dan Mar 06 '21 at 14:38
  • I understand your demand, but I think that keyboard shows just below the currently-typing `EditText` is a natural behavior in Android, just imagine your case, if there are other `View`s below the ADD `Button`, then when you want to type, there will be a huge gap between the `EditText` and your soft keyboard. For your case I would recommend using regular `AlertDialog` instead of `BottomSheetDialog`. – Sam Chen Mar 06 '21 at 14:48
  • Or, you can use `setOnEditorActionListener()` on the `EditText` to do the ADD action when user press the soft keyboard DONE key (at the bottom right corner). – Sam Chen Mar 06 '21 at 14:53

0 Answers0