我試圖設置顏色的按鈕,但是當我寫: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我沒有在任何地方看到 –
我有時候會閱讀你的問題,所以很迷惑你的真正問題是什麼? –