Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 为什么可以';不能应用thems.xml中的按钮样式吗?_Android_Styles_Themes - Fatal编程技术网

Android 为什么可以';不能应用thems.xml中的按钮样式吗?

Android 为什么可以';不能应用thems.xml中的按钮样式吗?,android,styles,themes,Android,Styles,Themes,我现在正试图将新字体应用于整个应用程序 顺便说一句,虽然样式标记是在主题.xml中定义的,但是文本视图是集体应用的,但是字体没有应用到其他视图,例如按钮和芯片 我只需要直接按下按钮,但是太麻烦了 而且该样式不能直接应用于芯片 原因是什么?这是虫子吗 themes.xml @颜色/紫色500 @颜色/浅色\绿色\深色 @颜色/白色 @颜色/青色200 @颜色/青绿色700 @颜色/黑色 ?attr/colorPrimaryVariant @样式/文本视图字体 @样式/按钮样式 @样式/芯片样式

我现在正试图将新字体应用于整个应用程序

顺便说一句,虽然
样式标记
是在
主题.xml
中定义的,但是
文本视图
是集体应用的,但是字体没有应用到其他视图,例如按钮和芯片

我只需要直接按下按钮,但是太麻烦了

而且该样式不能直接应用于
芯片

原因是什么?这是虫子吗

themes.xml


@颜色/紫色500
@颜色/浅色\绿色\深色
@颜色/白色
@颜色/青色200
@颜色/青绿色700
@颜色/黑色
?attr/colorPrimaryVariant
@样式/文本视图字体
@样式/按钮样式
@样式/芯片样式
@字体/机器人字体系列
假的
@字体/机械手
假的
@颜色/浅绿色
@字体/机械手
假的
roboto\u font\u family.xml


fragment\u body\u part\u dialog.xml


片段训练列表对话框.xml


您可以在材质主题中设置按钮样式:

   <item name="materialButtonStyle">@style/ButtonStyle</item>

   <style name="ButtonStyle" parent="Widget.MaterialComponents.Button">
       ...
@style/ButtonStyle
...

OMG..谢谢你,它确实有用。。但是芯片仍然不工作。我该怎么做?你直接在视图中设置芯片样式,style=“@style/CustomChipChoice”,这样它就不会从主题中获得。是的,这是我的错误。但是我删除了
style=“@style/CustomChipChoice”
这段代码,结果是一样的。
<?xml version="1.0" encoding="utf-8"?>
<font-family xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <!-- thin -->
    <font
        android:font="@font/roboto_thin"
        android:fontStyle="normal"
        android:fontWeight="100"
        app:font="@font/roboto_thin"
        app:fontStyle="normal"
        app:fontWeight="100"/>

    <!-- light -->
    <font
        android:font="@font/roboto_light"
        android:fontStyle="normal"
        android:fontWeight="300"
        app:font="@font/roboto_light"
        app:fontStyle="normal"
        app:fontWeight="300"/>

    <!-- regular -->
    <font
        android:font="@font/roboto_regular"
        android:fontStyle="normal"
        android:fontWeight="400"
        app:font="@font/roboto_black"
        app:fontStyle="italic"
        app:fontWeight="400" />
</font-family>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:backgroundTint="@color/light_green">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/border_dialog">
        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rcy_part"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            tools:listitem="@layout/body_part_item"/>
    </FrameLayout>

    <Button
        android:id="@+id/check"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:text="start"
        android:textSize="27dp"
        android:backgroundTint="@color/light_green"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <HorizontalScrollView
        android:id="@+id/horizontal_scroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toTopOf="@id/routine_list_recycler"
        android:scrollbars="none"
        android:overScrollMode="never">
        <com.google.android.material.chip.ChipGroup
            android:id="@+id/routine_chipgroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="10dp"
            app:chipSpacingHorizontal="10dp"
            app:singleLine="true"
            app:singleSelection="true"
            style="@style/ChipStyle">
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_back"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="BACK"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_chest"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="CHEST"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_leg"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="LEG"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_sholuder"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="SHOULDER"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_biceps"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="BICEPS"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_triceps"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="TRICEP"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
            <com.google.android.material.chip.Chip
                android:id="@+id/chip_abs"
                android:layout_width="55dp"
                android:layout_height="wrap_content"
                android:textAlignment="center"
                android:gravity="center_horizontal"
                android:text="ABS"
                app:rippleColor="@color/light_green"
                style="@style/CustomChipChoice"/>
        </com.google.android.material.chip.ChipGroup>
    </HorizontalScrollView>

    <View
        android:id="@+id/horizontal_bar"
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:background="@color/light_green"
        app:layout_constraintTop_toBottomOf="@id/horizontal_scroll"
        app:layout_constraintBottom_toTopOf="@id/routine_list_recycler"/>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/routine_list_recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/horizontal_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
   <item name="materialButtonStyle">@style/ButtonStyle</item>

   <style name="ButtonStyle" parent="Widget.MaterialComponents.Button">
       ...