簡體   English   中英

在按鈕上制作圓角的 xml 不起作用

[英]xml to make rounded corners on button is not working

我的應用程序中有許多圓角按鈕,但我的一些按鈕不適用於任何類型的背景,無論是圓角還是更改顏色都無關緊要。 這是 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/colorAppBackground"
    tools:context=".activities.GameActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:orientation="horizontal"
        android:weightSum="10">

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2" />


        <TextView
            android:id="@+id/textViewGameCategory"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="6"
            android:gravity="center"
            android:textSize="28sp"
            android:textColor="@color/colorBlack"
            tools:text="Gemälde"/>


        <TextView
            android:id="@+id/textViewGameCounter"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:gravity="center"
            android:textSize="20sp"
            tools:text="9/107"/>
    </LinearLayout>

    <View style="@style/Divider" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="10">

        <TextView
            android:id="@+id/textViewGameQuestion"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_marginStart="15dp"
            android:layout_marginLeft="15dp"
            android:layout_marginEnd="15dp"
            android:layout_marginRight="15dp"
            android:layout_weight="1.5"
            android:gravity="center"
            android:textSize="20sp"
            android:textColor="@color/colorBlack"
            tools:text="Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam"/>

        <ImageView
            android:id="@+id/imageViewCardFlip"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:paddingStart="15dp"
            android:paddingLeft="15dp"
            android:paddingEnd="15dp"
            android:paddingRight="15dp"
            android:paddingBottom="15dp"
            android:layout_weight="3.5"
            android:src="@drawable/cover_quizgame" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:layout_weight="5"
            android:weightSum="2">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="horizontal"
                android:weightSum="2">


                <Button
                    android:id="@+id/buttonGameOptionOne"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginEnd="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="1"
                    android:textSize="12sp"
                    android:gravity="center"
                    android:textAllCaps="false"
                    android:padding="3dp"
                    android:background="@drawable/btn_answer_rounded_corners" />

                <Button
                    android:id="@+id/buttonGameOptionTwo"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="1"
                    android:textSize="12sp"
                    android:gravity="center"
                    android:textAllCaps="false"
                    android:padding="3dp"
                    android:background="@drawable/btn_answer_rounded_corners" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:orientation="horizontal"
                android:weightSum="2">


                <Button
                    android:id="@+id/buttonGameOptionThree"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="15dp"
                    android:layout_marginLeft="15dp"
                    android:layout_marginEnd="5dp"
                    android:layout_marginRight="5dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="1"
                    android:textSize="12sp"
                    android:gravity="center"
                    android:textAllCaps="false"
                    android:padding="3dp"
                    android:background="@drawable/btn_answer_rounded_corners" />

                <Button
                    android:id="@+id/buttonGameOptionFour"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_marginStart="5dp"
                    android:layout_marginLeft="5dp"
                    android:layout_marginEnd="15dp"
                    android:layout_marginRight="15dp"
                    android:layout_marginTop="5dp"
                    android:layout_marginBottom="5dp"
                    android:layout_weight="1"
                    android:textSize="12sp"
                    android:gravity="center"
                    android:textAllCaps="false"
                    android:padding="3dp"
                    android:background="@drawable/btn_answer_rounded_corners" />
            </LinearLayout>

            <Button
                android:id="@+id/buttonContinue"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginStart="70dp"
                android:layout_marginLeft="70dp"
                android:layout_marginEnd="70dp"
                android:layout_marginRight="70dp"
                android:layout_marginBottom="15dp"
                android:layout_marginTop="15dp"
                android:background="@drawable/btn_continue_rounded_corners"
                android:text="@string/singlegame_continue" />

            <ProgressBar
                android:id="@+id/progressBarSingleGame"
                style="?android:attr/progressBarStyleHorizontal"
                android:layout_width="match_parent"
                android:layout_height="40dp"
                android:layout_marginStart="15dp"
                android:layout_marginLeft="15dp"
                android:layout_marginEnd="15dp"
                android:layout_marginRight="15dp"
                android:layout_marginBottom="15dp"
                android:layout_marginTop="15dp"
                android:progressDrawable="@drawable/progressbar_greenprogress"
                android:visibility="gone"
                />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

ID 為“buttonGameOption*”的按鈕設置了背景“btn_answer_rounded_corners”。 在預覽中,角是圓角的,但是當我啟動應用程序時,按鈕仍然沒有圓角。 這里是 XML 文件

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item>
            <layer-list>
                <item android:right="1dp" android:top="1dp" android:bottom="1dp"      android:left="1dp">
                    <shape>
                        <corners android:radius="10dp"></corners>
                        <solid android:color="@color/colorNotAnswered"></solid>
                    </shape>
                </item>
            </layer-list>
        </item>
    </selector>

有人可以告訴我如何解決這個問題嗎?

我已經檢查了你的代碼並且沒有任何問題。 檢查您的活動主題,或者您可能以編程方式對按鈕執行某些操作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM