NIr*_*mar 3 android android-fragments
我有一个应用程序,其中我有一个MainActivity,其中包含一个扩展BottomSheetDialogFragment的片段.我想设置片段主题,但它保持不变.请帮助
扩展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>
Run Code Online (Sandbox Code Playgroud)
这里我使用的是android:theme ="@ style/CoffeeDialog",但它不起作用.
主题代码: -
<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>
Run Code Online (Sandbox Code Playgroud)
注意: - 我只想更改片段主题,而不是MainActivity.
Ris*_*esh 11
尝试下面给出的代码
public class CustomDialogFragment extends BottomSheetDialogFragment {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(STYLE_NORMAL, R.style.CoffeeDialog);
}
...
}
Run Code Online (Sandbox Code Playgroud)
CoffeeDialog
将成为你的主题 styles.xml
小智 8
getTheme
在您的片段中使用如下方法添加主题:
override fun getTheme(): Int {
return R.style.CustomBottomSheetDialog
}
Run Code Online (Sandbox Code Playgroud)