为什么按编程方式添加按钮样式会更改?

时间:2017-04-22 22:57:54

标签: android xml

我在滚动视图中有一个按钮列表,但是当我以编程方式添加其他按钮时,风格不同,我不知道为什么。 正如我们在下一张图片中看到的,添加的按钮更暗,当我点击按钮时,按钮的背景变为蓝色。 但我的默认按钮是深灰色。

有捕获:

enter image description here

按钮" 6"是XML按钮添加。另一个是以编程方式添加的。

有我的XML:

    curl --proxy-insecure -x https://username:password@xxx.xxx.xxx.xxx:443 https://api.ipify.org/?format=text

我的代码中添加了按钮:

TableLayout sv =(TableLayout)findViewById(R.id.tableLayout1);

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/diese">


    <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
        <ScrollView
                    android:id="@+id/scrollView"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="50dp">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@android:color/darker_gray" >

            <TableLayout
                    android:id="@+id/tableLayout1"
                    android:layout_width="match_parent"
                    android:layout_height="700dp" >

               <TableRow
                        android:layout_height="0dp"
                        android:layout_weight="1" >

                    <Button
                            android:id="@+id/one"
                            android:layout_width="0dp"
                            android:layout_height="fill_parent"
                            android:layout_weight="1"
                            android:gravity="center"
                            android:text="1" />
                </TableRow>

很多。背景&#34;这个&#34;参考我的ButtonActivity。

1 个答案:

答案 0 :(得分:0)

你应该告诉我们你的风格档案和Diese课程吗?我觉得这是一个风格问题。

但是根据提供的信息,我几乎可以肯定“addDieseToXml”或Diese类本身定义了按钮样式,并且你没有将这种样式应用于你的xml按钮(正如你所说深灰色是你的颜色)想要的)。

因此,我建议您使用

将样式应用于按钮
style="@style/YourStyle"

直接在XML按钮代码中。

其他选项是通过更改主题,添加

,将此样式应用于所有活动按钮(如果需要)
<item name="android:buttonStyle">@style/YourStyle</item>