Lar*_*ars 7 android android-dialogfragment kotlin
我有一个活动,我的用户可以为实体编辑不同的值.我创建了一个BottomSheetDialogFragment,用户可以在其中更改所述实体的某些时间值.
当用户更改值(这是时间)时,我想更改活动在后台显示的值.但是,当我更新我的活动视图时,整个活动会像这样跳过状态栏(我知道所选数字与显示的数字之间存在不一致,这是我尚未修复的时区事项).
我打开BottomSheetDialigFragment:
TimePickerDialogFrag.newInstance(shift!!, type).run {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
show(supportFragmentManager, "timepicker_modal")
}
Run Code Online (Sandbox Code Playgroud)
BottomSheetDialogFragment通过名为OnTimeChangedListener的接口与活动进行通信,如下所示:
override fun onAttach(context: Context) {
super.onAttach(context)
if (context is OnTimeChangedListener) {
listener = context
} else {
throw RuntimeException(context.toString() + " must implement OnTimeChangedListener")
}
}
override fun onDetach() {
super.onDetach()
listener = null
}
interface OnTimeChangedListener {
fun onTimeChanged(shift: ShiftEntity)
}
Run Code Online (Sandbox Code Playgroud)
当用户旋转TimePicker小部件时,将调用onTimeChanged方法.
该方法在活动中实现为:
override fun onTimeChanged(shift: ShiftEntity) {
this.shift = shift
startTimeTextView?.text = TimeFormatter.formatTime(shift.startTime, "HH:mm")
endTimeTextView?.text = TimeFormatter.formatTime(shift.endTime, "HH:mm")
}
Run Code Online (Sandbox Code Playgroud)
我猜解决方案是在Activitys布局文件中的某个位置,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
android:focusableInTouchMode="true"
tools:context=".activities.myshifts.ShiftActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
style="@style/myNavDrawer"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="@color/primaryBg"
android:contentInsetEnd="0dp"
android:contentInsetLeft="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
app:contentInsetEnd="0dp"
app:contentInsetEndWithActions="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp"
app:contentInsetStartWithNavigation="0dp"
app:popupTheme="@style/AppTheme"
app:theme="@style/ToolbarColoredBackArrow">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
//Content of custom AppBar goes here. Removed for an easier overview
</android.support.constraint.ConstraintLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
//Actual content of activity goes here. Removed it for an easier
overview, will add if needed.
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我已经尝试使用android:fitsSystemWindows ="true"属性 - 将其添加到父视图和AppBarLayout.
它添加到父布局创建AppBar的内部填充,只要打开片段,就像在上面看到这里
将属性添加到AppBarLayout没有任何区别.
我找到了解决方案。我没有意识到我膨胀 BottomSheetDialogFragment 的方式会产生影响,因此我最初没有在问题中包含该代码。
然而,window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)从 Fragment 中删除却成功了。
| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |