我想将“持久性底页”制作为片段内的片段,但找不到任何方法来实现。到处都添加了“持久性底部工作表”作为活动/碎片内部的布局,但是是否可以将“持久性底部工作表”作为片段,以便我可以在其他地方重复使用该视图?
答案 0 :(得分:0)
AndroidHive中有一个关于BottomSheet
的精彩教程
您可以创建扩展BottomSheetDialogFragment
的类。
public class BottomSheetFragment extends BottomSheetDialogFragment {
public BottomSheetFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_bottom_sheet_dialog, container,
false);
}
}
并使用以下代码对其进行切换
BottomSheetFragment bottomSheetFragment = new BottomSheetFragment();
bottomSheetFragment.show(getSupportFragmentManager(), bottomSheetFragment.getTag());
答案 1 :(得分:-2)
you can use BottomSheetDialogFragment,
I imagine you want to do just like this: [https://cdn-images-1.medium.com/max/800/1*rLBf6fPtfWhXqnTOLlj0cQ.png][1]
create the navigationView file
<?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="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:itemBackground="@drawable/state_pressed"
app:menu="@menu/activity_main_drawer" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
and create file menu
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_camera"
android:icon="@drawable/round_home_24"
android:title="Inicio"
android:checked="true"
android:checkable="true"/>
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/outline_settings_24"
android:title="Configuración"
android:checkable="true"/>
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/round_mail_outline_24"
android:title="Email"
android:checkable="true"/>
<item
android:id="@+id/nav_manage"
android:icon="@drawable/outline_search_24"
android:title="Buscar" />
</group>
<item android:title="Communicate">
<menu>
<item
android:id="@+id/nav_share"
android:icon="@drawable/outline_lock_24"
android:title="Share" />
<item
android:id="@+id/nav_send"
android:icon="@drawable/outline_account_circle_24"
android:title="Send" />
</menu>
</item>
</menu>
and create the file for borderRadius
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff0000" />
<corners android:bottomRightRadius="90dp" android:bottomLeftRadius="90dp" />
<padding android:left="30dp"/>
</shape>
</item>
<item android:state_checked="false">
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent" />
<corners android:bottomRightRadius="30dp" android:topRightRadius="30dp" />
</shape>
</item>
</selector>
and create state_pressed backgroud color
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/border_radius_tabs">
<color android:color="@color/colorPrimary"></color>
</item>
<item android:state_checked="false">
<color android:color="@color/primaryLightColor"></color>
</item>
</selector>