我在我的应用程序中使用ScrollingActivity,并且使用BottomSheetDialog。 在最底下的对话框中是edittextes,我希望对话框 出现键盘时,它会在键盘上方移动。
我正在尝试所有其他解决方案,但是没有任何效果。 我进行了一个空的活动并放入清单
android:windowSoftInputMode="adjustResize"
,它可以正常工作,但不是 在我的滚动活动中。
PocketMain.java
public class PocketMain extends AppCompatActivity {
// Layouts
CoordinatorLayout coordinatorLayoutPocketMain;
// Database
Database database;
// Recyclerview
List<Pocket> PocketItems = new ArrayList<>();
RecyclerView recyclerViewPocketItems;
// Buttons
Button button2,button3;
@Override
protected void onCreate(Bundle savedInstanceState) {
// Removes the black shadow on the status bar
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pocket_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
// Removes the text from the actionbar
Objects.requireNonNull
(getSupportActionBar()).setDisplayShowTitleEnabled(false);
// assign variables
coordinatorLayoutPocketMain = findViewById(R.id.coordinatorLayoutPocketMain);
button2 = findViewById(R.id.button2);
button3 = findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(PocketMain.this,MainActivity.class);
startActivity(i);
}
});
final BottomSheetDialog d = new BottomSheetDialog(this);
Objects.requireNonNull(d.getWindow()).setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
d.setContentView(R.layout.content_bottomsheet_new_pocket_item);
d.getBehavior().setHideable(true);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
d.show();
}
});
}
}
ActivityPocketMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayoutPocketMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".PocketMain">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
android:theme="@style/AppTheme.AppBarOverlay">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:toolbarId="@+id/toolbar">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_marginTop="22dp"
app:layout_collapseMode="pin"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="75dp"
android:layout_gravity="bottom">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_pocket_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
ContentPocketMain.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".PocketMain"
tools:showIn="@layout/activity_pocket_main">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerviewPocketItem"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.core.widget.NestedScrollView>