我正在使用BottomSheetBehavior原始支持库:
implementation 'com.android.support:design:27.1.1'
Run Code Online (Sandbox Code Playgroud)
当我迁移使用新androidx库时虽然BottomSheetBehavior缺少了.上述支持库的映射也不在AndroidX重构列表中,但迁移工具将其删除.
我错过了将BottomSheetBehavior包含在新androidx库中.
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.google.android.material:material:1.0.0-beta01'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// ReactiveX
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'io.reactivex.rxjava2:rxkotlin:2.2.0'
implementation 'com.android.support:design:28.1.0'
// Android Compatability Libraries
// Version: https://developer.android.com/topic/libraries/support-library/refactor
implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0-beta01'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-beta01'
implementation 'androidx.recyclerview:recyclerview:1.0.0-beta01'
// Android Navigation Component
// Check here for updated version info - will move to androidx soon.
// https://developer.android.com/topic/libraries/architecture/adding-components
def nav_version = "1.0.0-alpha04"
// use -ktx for Kotlin
implementation …Run Code Online (Sandbox Code Playgroud) 我有一个自定义的BttomSheetDialogFragment,我希望在底部视图的顶部有圆角
这是我的自定义类,它让我希望从底部显示我的布局
View mView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.charge_layout, container, false);
initChargeLayoutViews();
return mView;
}
Run Code Online (Sandbox Code Playgroud)
我也有这个xml资源文件作为背景:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners android:topRightRadius="35dp"
android:topLeftRadius="35dp"
/>
<solid android:color="@color/white"/>
<padding android:top="10dp"
android:bottom="10dp"
android:right="16dp"
android:left="16dp"/>
Run Code Online (Sandbox Code Playgroud)
但问题是,当我将此资源文件设置为我的Layout的根元素的背景时,角落仍然没有舍入
我不能使用下面的代码:
this.getDialog().getWindow().setBackgroundDrawableResource(R.drawable.charge_layout_background);
Run Code Online (Sandbox Code Playgroud)
因为它覆盖BottomSheetDialog的默认背景,并且在我的底视图上方不会有任何半透明的灰色
android material-design bottom-sheet material-components material-components-android
我创建了一个BottomSheetDialogFragment,我想调整它的最大扩展高度.我怎样才能做到这一点?我可以找回BottomSheetBehaviour但是我能找到的只是一个用于窥视高度的二传手,但是对于扩展的高度没什么.
public class DialogMediaDetails extends BottomSheetDialogFragment
{
@Override
public void setupDialog(Dialog dialog, int style)
{
super.setupDialog(dialog, style);
View view = View.inflate(getContext(), R.layout.dialog_media_details, null);
dialog.setContentView(view);
...
View bottomSheet = dialog.findViewById(R.id.design_bottom_sheet);
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setPeekHeight(...);
// how to set maximum expanded height???? Or a minimum top offset?
}
}
Run Code Online (Sandbox Code Playgroud)
编辑
我为什么需要那个?因为我BottomSheet在一个全屏活动中显示一个Dialog,如果BottomSheet在顶部留下一个空间,它看起来很糟糕......
android android-support-library androiddesignsupport bottom-sheet
我想要实现的是类似于 Instagram 应用程序内网络浏览器,当您点击广告时使用:
我所做的,是我使用了一个 WebView bottomSheetDialogFragment,然后我重写onCreateDialog以获得这样的全屏:
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
BottomSheetDialog bottomSheetDialog=(BottomSheetDialog)super.onCreateDialog(savedInstanceState);
bottomSheetDialog.setOnShowListener(dialog -> {
BottomSheetDialog dialogc = (BottomSheetDialog) dialog;
FrameLayout bottomSheet = dialogc .findViewById(android.support.design.R.id.design_bottom_sheet);
BottomSheetBehavior.from(bottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
//BottomSheetBehavior.from(bottomSheet).setSkipCollapsed(true);
//BottomSheetBehavior.from(bottomSheet).setHideable(true);
});
return bottomSheetDialog;
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:
我的问题是,如何获得全屏效果,或者如何实现类似 instagram 浏览器的功能?
ps:我首先尝试了 chrome 自定义选项卡,但无法将其添加到对话框片段中。
谢谢你。
android material-design bottom-sheet material-components material-components-android
更新
我想完成谷歌地图与支持库23.x. +并且没有任何第三个库的相同行为
注意:这不是一个重复的问题,因为:
我已经有官方的bottomSheet工作(甚至在选项卡和视图寻呼机内).
令我发疯的是如何在使用官方bottomSheet向上滑动时实现BottomSheet的图像行为?.
我尝试使用像FAB这样的锚没有成功.
我读了一些关于使用滚动监听器的内容,但是ppl说它不像谷歌地图那样平滑和快速.
我的XML(我不认为它会有所帮助,但无论如何):
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MasterActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways|snap">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/borderlessButtonStyle"
android:text="Departure"
android:layout_gravity="center"
android:id="@+id/buttonToolBar"
/>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabBackground="@android:color/white"
app:tabTextColor="@color/colorAccent"
app:tabSelectedTextColor="@color/colorAccent"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/asdf"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:behavior_peekHeight="100dp"
android:fitsSystemWindows="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:id="@+id/qwert"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="16dp"
android:background="@android:color/white"
android:padding="15dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我知道BottomSheetDialog已经这样做了,但我需要使用BottomSheet从中生成的常规和行为BottomSheetBehavior.from().这BottomSheet不会使背景变暗,而且外面的触摸也不会将其关闭.有没有办法在BottomSheet显示时调暗背景?当外面碰到时可能会解雇.基本上行为就像BottomSheetDialog但我必须BottomSheet BottomSheetBehavior直接使用.
谢谢!
我在扩展BottomSheetDialogFragment的整个类中出错
Cannot access 'androidx.lifecycle.HasDefaultViewModelProviderFactory' which is a supertype of 'FavoriteBottomDialogFragment'. Check your module classpath for missing or conflicting dependencies
Run Code Online (Sandbox Code Playgroud)
该类位于 app 模块中,该模块实现了另外两个模块:core 和presentation-core
构建.gradle
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project (':core')
implementation project (':presentation-core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.41"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
testImplementation 'junit:junit:4.12'
implementation "com.google.android.material:material:1.1.0"
//Rx
implementation "io.reactivex.rxjava2:rxandroid:2.1.1"
implementation "io.reactivex.rxjava2:rxjava:2.2.9"
//Architecture component
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.room:room-runtime:2.0.0'
kapt 'androidx.room:room-compiler:2.0.0'
kapt 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
implementation 'androidx.room:room-rxjava2:2.0.0'
implementation 'androidx.room:room-guava:2.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
}
Run Code Online (Sandbox Code Playgroud)
核心依赖
dependencies {
api fileTree(dir: 'libs', include: …Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android应用程序,并BottomNavigationView从设计库中实现.我看了很多例子,我无法弄清楚我的布局有什么问题.在BottomNavigationView不显示为全宽.
另一个问题是状态栏颜色未应用.
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
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">
<!-- Include the toolbar -->
<include layout="@layout/toolbar"/>
<RelativeLayout android:id="@+id/fragment_container"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@android:color/white"
app:itemTextColor="@android:color/white"
app:menu="@menu/bottom_navigation_main"/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
toolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
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="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)
编辑:添加了未设置状态颜色的解决方案
android:fitsSystemWindows="true"
我用NestedScrollView实现了底部表现行为.并且想知道在外面触摸时是否可以隐藏底部视图.
我有BottomSheetFragmentActivity这导致在Android 8.0设备此崩溃.我正在寻找一种解决方法,而不是将targetSDK设置回26.
我解释了这里所描述的:但这反过来导致了
SurfaceFlinger:无法在图层父级(无父级)中找到图层BottomSheetFragmentActivity#0.
有解决方案吗?
bottom-sheet ×10
android ×9
androidx ×2
material-components-android ×2
classpath ×1
dependencies ×1
google-maps ×1
parallax ×1