嗨,大家好,我是android的新手,当颜色更改时,我遇到了一个按钮问题,因为当按钮更改时,按钮长了一点,我不知道为什么。我的按钮点击代码如下。
produzirbt.setBackgroundColor(Color.rgb(38, 198, 219));
Toast.makeText(getApplicationContext(), "Avaria iniciada.", Toast.LENGTH_SHORT).show();
Xml
<Button
android:layout_width="150dp"
android:layout_height="100dp"
android:text="Pausa"
android:id="@+id/Pausa"
android:textSize="50px"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_above="@+id/Avaria"
android:layout_toRightOf="@+id/terminaliniciado"
android:layout_toEndOf="@+id/terminaliniciado" />
为了保持按钮大小使用setColorFilter()
方法。
在您的情况下:
produzirbt.getBackground().setColorFilter(ContextCompat.getColor(this, R.color.your_color), PorterDuff.Mode.SRC_ATOP);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句