android - 状态展开的底片圆角
问题描述
我面临一个特定的问题。我有一个 bottomSheet,我想在 TopLeft 和 TopRight 角上放置一个半径。除非 bottomSheet.state 为STATE_EXPANDED
. 所以我找到了这个解决方案
@SuppressLint("RestrictedApi", "VisibleForTests")
override fun onCreateDialog(savedInstanceState: Bundle?): BottomSheetDialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.behavior.disableShapeAnimations()
return bottomSheetDialog
}
但问题是:在我的bottomSheet 中,我有一个EditText 和一个按钮。使键盘在按钮下方,我必须在我的onCreateDialog
方法中添加这行代码
bottomSheetDialog.behavior.state = STATE_EXPANDED
所以当我添加它时,由于某种原因,角落不再是圆的......
在这里你可以找到我当前的代码:
@SuppressLint("RestrictedApi", "VisibleForTests")
override fun onCreateDialog(savedInstanceState: Bundle?): BottomSheetDialog {
val bottomSheetDialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog
bottomSheetDialog.behavior.disableShapeAnimations()
bottomSheetDialog.behavior.state = STATE_EXPANDED
return bottomSheetDialog
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetStyle)
}
在这里我的Style
<style name="BottomSheetStyle" parent="Theme.Design.Light.BottomSheetDialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowSoftInputMode">adjustResize</item>
</style>
你知道我能做些什么来完成这项工作吗?bottomSheetDialog.behavior.disableShapeAnimations()
解决方案
尝试使用以下代码。
//create round_dialog.xml inside drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners
android:bottomLeftRadius="24dp"
android:bottomRightRadius="24dp"
android:topLeftRadius="24dp"
android:topRightRadius="24dp" />
</shape>
// update you theme file
<style name="AddDocBottomSheetDialogTheme"
parent="Theme.Design.Light.BottomSheetDialog">
<item name="bottomSheetStyle">@style/AppModalStyle</item>
</style>
<style name="AppModalStyle"
parent="Widget.Design.BottomSheet.Modal">
<item name="android:background">@drawable/rounded_dialog</item>
<item name="android:layout_marginHorizontal">15dp</item>
</style>
// Dialog class
class TestDialogFragment : BottomSheetDialogFragment() {
private lateinit var binding: TestDialogFragmentBinding
override fun getTheme(): Int {
return R.style.AddDocBottomSheetDialogTheme
}
}
推荐阅读
- http - 跨 EJB(有状态会话 Bean)与 HTTP 会话与现代框架的会话信息
- android - Wear OS 通知振动和声音
- node.js - 如何在 Node.js 中使用 Telegram 的 TDlib
- haskell - 根据 (maxBound :: Int) 的运行时值进行类型约束
- informatica - 在 Informatica 中工作时出现 FR_3085 错误
- c++ - 在 C++ 中自动生成方法
- xamarin - 如何使用计时器禁用 UIButton
- mysql - 尝试根据日期查找表的最大行时返回奇怪的值
- javascript - 确认框 OK/Cancel 功能
- java - 执行文件搜索后具有更新值的 JTable