【发布时间】:2016-05-08 21:23:29
【问题描述】:
我想显示一个小于屏幕宽度的底部工作表对话框。
例如,Nexus 9 上 Google Play 音乐的分享选项。
你知道如何做到这一点吗?
现在我只是成功地减小了工作表内容的宽度,但背景仍然是屏幕宽度并显示为白色背景。
一些代码:
build.gradle
compile 'com.android.support:design:23.3.0'
主活动
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mBottomSheetDialog = new BottomSheetDialog(this);
mBottomSheetDialog.setContentView(R.layout.sheet_test);
mBottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mBottomSheetDialog = null;
}
});
mBottomSheetDialog.show();
}
sheet_test
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="100dp"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Some Text"
android:textColor="@color/colorPrimary" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" />
<TextView
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="16dp"
android:text="Some Text" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#ddd" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
【问题讨论】:
-
请分享一些代码:)
-
您使用的是什么版本的设计库?你试过最新的(23.3.0)吗?
-
我认为您只需要使父活动透明即可。参考stackoverflow.com/questions/2176922/…
-
好的,所以我必须添加一个活动来显示我的底部工作表视图?现在,我从一个显示一些业务信息的活动创建我的 BottomSheetDialog,因此不透明。
-
您找到解决方案了吗?我也坚持这一点。
标签: android