我试图设置颜色的按钮,但是当我写:setBackgroundColor改变了更多的颜色,然后单击按钮
button.setBackgroundColor(getResources().getColor(R.color.white));
按钮变成白色,而且周围的一些空间(我有几个按钮在linearLayout
,所以它看起来像一个大的白色按钮)。
任何人都知道如何解决这个问题?
更新:我的XML:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:weightSum="2"
android:layout_weight="1"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:background="@android:color/white"
android:id="@+id/button1"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="@+id/button2"
/>
</LinearLayout>
这里左边的按钮看起来更大然后是正确的,因为我改变了它的颜色
请添加您的xml代码! – hasan83
你的按钮的ID在哪里?你如何在Java中初始化它!什么是@ + id/logo我没有在任何地方看到 –
我有时候会阅读你的问题,所以很迷惑你的真正问题是什么? –