Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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 如何在选择器中使用样式?_Android_Android Ui - Fatal编程技术网

Android 如何在选择器中使用样式?

Android 如何在选择器中使用样式?,android,android-ui,Android,Android Ui,我想在按下选择器状态_时增加按钮的文本大小,并将其设置为其他状态的正常大小 请帮助了解如何使用状态的样式?我在选择器中找不到任何选项 现在我只是用选择器改变背景颜色,让我知道我们是否可以在选择器中使用样式,这样可以通过样式改变文本大小 // fragment's xml <Button android:id="@+id/btn_level3" android:text="@string/level3" android:text

我想在按下选择器状态_时增加按钮的文本大小,并将其设置为其他状态的正常大小

请帮助了解如何使用状态的样式?我在选择器中找不到任何选项

现在我只是用选择器改变背景颜色,让我知道我们是否可以在选择器中使用样式,这样可以通过样式改变文本大小

    // fragment's xml
    <Button
        android:id="@+id/btn_level3"
        android:text="@string/level3"
        android:textColor="#99CC00"
        style="@style/ButtonNormal"
        android:background="@drawable/button_custom"/>           

-----------------------------------------------------------

    // styles.xml
    <style name="ButtonPressed">
        <item name="android:textSize">@dimen/button_pressed</item>
    </style>

-----------------------------------------------------------

    // buttom_custom.xml
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true" android:drawable="@drawable/color_highlight" />
        <item android:state_focused="true" android:drawable="@android:color/transparent" />
        <item android:drawable="@android:color/transparent" />
    </selector>
//片段的xml
-----------------------------------------------------------
//styles.xml
@尺寸/按钮按下
-----------------------------------------------------------
//buttom_custom.xml

您可以使用按钮上的setOnTouchListener方法设置按钮宽度和高度。参考这个

亚马赫迪aj --在drawable中创建btn.xml,然后粘贴:


<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="false">
            <shape android:shape="oval">
                <solid android:color="@color/formbtn"/>
                <stroke android:width="10dp" android:color="@color/transparent" />

            </shape>
        </item>
        <item android:state_pressed="true">
            <shape android:shape="oval">
                <solid android:color="@color/formbtnborder"/>
                <stroke android:width="10dp" android:color="@color/transparent" />
            </shape>
        </item>
    </selector>