Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set theme in fragment extends BottomSheetDialogFragment?

I have an app in which i have a MainActivity which contains a fragment that extends BottomSheetDialogFragment. What I want to set fragment theme but it remains same.Pls help

Code for fragment that extends BottomSheetDialogFragment:-

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottomSheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:theme="@style/CoffeeDialog">

<de.hdodenhof.circleimageview.CircleImageView
    android:id="@+id/img_Camera"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_gravity="center_horizontal|bottom"
    android:layout_marginTop="10dp"
    android:src="@drawable/amazon"
    app:civ_border_color="@color/textColor"
    app:civ_border_width="5dp"
    app:civ_fill_color="@color/colorPrimary" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/notification_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="8dp" />

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="30dp">

</FrameLayout>

here i am using android:theme="@style/CoffeeDialog" but it's not working.

Code for theme:-

  <style name="CoffeeDialog" parent="Theme.Design.Light.BottomSheetDialog">
    <item name="android:windowCloseOnTouchOutside">false</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:colorBackground">@android:color/transparent</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:backgroundDimAmount">0.3</item>
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
</style>

Note:- I only want to change fragment theme, not MainActivity.

like image 582
NIraj Kumar Avatar asked Jan 06 '18 18:01

NIraj Kumar


People also ask

How do I set styles in BottomSheetDialogFragment?

public class CustomDialogFragment extends BottomSheetDialogFragment { @Override public void onCreate(@Nullable Bundle savedInstanceState) { super. onCreate(savedInstanceState); setStyle(STYLE_NORMAL, R. style.

How do you fully expand the bottom sheet dialog in Android?

Bottom sheets are set to STATE_COLLAPSED at first. Call BottomSheetBehavior#setState(STATE_EXPANDED) if you want to expand it. Note that you cannot call the method before view layouts.

How do I disable BottomSheetDialogFragment dragging?

Disable drag of BottomSheetDialogFragment It can also be disabled by overriding onStateChanged() . This will set the expanded state even if user drags the view.

How to show dialog fragment in activity?

Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.


1 Answers

In your fragment add your theme with the getTheme method like this:

override fun getTheme(): Int {
        return R.style.CustomBottomSheetDialog
    }
like image 71
lonly night Avatar answered Nov 01 '22 12:11

lonly night