0

基本的に、ボタンに背景色を追加すると、角丸要素が消えるため、基本的に角丸はありません。しかし、背景色がない場合、ボタンの角が丸くなってしまいます。

何が起こっているのかわかりません。助けてください

4

3 に答える 3

2

境界線はデフォルトの背景ドローアブルの一部であるため、これが必要な場合も、境界線を含むものに置き換える必要があります。デフォルトの背景リソースを取得し、編集して色を付けます。あるいは、使用することができます

    button = (Button) findViewById(R.id.button);
    button.getBackground().setColorFilter(color, Mode.SRC_ATOP);

これはおそらく、期待に近いものを提供します。

于 2013-03-02T23:02:46.203 に答える
1
    <?xml version="1.0" encoding="utf-8"?>
        <selector xmlns:android="http://schemas.android.com/apk/res/android" >
                <item android:state_enabled="false">
                    <shape xmlns:android="http://schemas.android.com/apk/res/android"
                        android:padding="10dp" android:shape="rectangle">
                        <solid android:color="#FFb888"/>
                        <corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
                    </shape>            
                </item>

                <item android:state_enabled="true" android:state_pressed="true">
                    <shape xmlns:android="http://schemas.android.com/apk/res/android"
                        android:padding="10dp" android:shape="rectangle">
                        <solid android:color="#FFD488"/>
                        <corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp" android:topRightRadius="15dp"/>
                    </shape>            
                </item>

                <item android:state_enabled="true">
                    <shape xmlns:android="http://schemas.android.com/apk/res/android"
                        android:padding="10dp" android:shape="rectangle">
                        <solid android:color="#FF8C00"/>
                        <corners android:bottomLeftRadius="15dp" android:bottomRightRadius="15dp" android:topLeftRadius="15dp"    android:topRightRadius="15dp"/>
                    </shape>            
                </item>
        </selector>

    <Button
    android:id="@+id/btn_add_list"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:background="@drawable/rounded_orange_button"
    android:text="@string/action_new_list"
    android:textColor="@color/white"
    android:gravity="center"
    android:textSize="18sp"
    android:layout_marginTop="20dp"
    android:layout_marginRight="10dp"
    android:layout_alignParentRight="true"               
    android:onClick="doNewList"/>

ボタンの背景となる上記のxmlファイルを、res/drawableフォルダーのrounded_orange_button.xmlというファイルに保存できます。したがって、res / drawable/rounded_orange_button.xmlになります。これにより、ユーザーがボタンを選択したときにボタンのフィードバックも提供されます。developer.android.comのdsignガイドラインにもう少し厳密に従いますが、これはユーザーの好みです。猫の皮を剥ぐ方法は無数にあります。次に、2番目の例でyour_layout.xmlファイル内のdrawableフォルダーに作成したものを参照します。色の値はオプションであり、必要に応じてres / values/colors.xmlの別のリソースファイルから設定することもできます。ボタン内に表示する文字列には、res / values/strings.xmlを使用します。お役に立てれば。また、ボタンの曲線の量は、の半径値で遊ぶことによって調整できます。

于 2013-03-04T12:32:24.013 に答える
0

ボタンの背景は角が直角になります。素敵なカスタム背景については、背景画像を作成し、ボタンの背景または src として使用することをお勧めします。したがって、xml は次のようになります。

android:src="@drawable/mybuttonimage"
android:bacgkround="@null"

また

android:background="@drawable/mybuttonimage"

画像を異なる方法で引き伸ばすことができるので、両方をテストします。

もう 1 つのオプションは、res/drawable フォルダーに形状を作成することです。

<?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <solid android:color="#33DDFF" />
        <corners android:radius="4dp" />
    </shape>
于 2013-03-02T23:00:22.567 に答える