【发布时间】:2014-01-10 02:50:00
【问题描述】:
我在 xml 中为切换按钮上的可绘制右侧设置了一个圆形(形状)。 circle.xml 的初始颜色为绿色,但我无法让它显示在按钮上。当我使用图像时,我能够看到图像,所以我确定问题出在圆形或形状上。 这是他用可绘制的权利切换按钮。
<ToggleButton
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="@drawable/custom_fixture_buttons"
android:textColor="@drawable/white"
android:textOff="F1"
android:textOn="F1"
android:drawableRight="@drawable/circle"
android:textSize="30sp" />
这是 circle.xml 的代码
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/circle"
android:shape="oval"
android:color="#ff00FFFF" >
</shape>
我总共有 10 个带有可绘制权限的切换按钮,需要分别更改每个按钮的颜色,这是设置每个颜色点的方法。第一代在每个按钮上使用了单独的图像,但我需要更改代码以将其应用于切换按钮 drawableright。我尝试了 setCompoundDrawablesWithIntrinsicBounds 但出现错误。
switch (index) {
case 0: {
Resources res = getResources();
final Drawable drawable = res.getDrawable(R.drawable.circle);
drawable.setColorFilter(Color.rgb(i, j, k), Mode.SRC_ATOP);
// ImageView img = (ImageView) findViewById(R.id.colordot1);
// img.setBackgroundDrawable(drawable);
// Fixture1.setCompoundDrawablesWithIntrinsicBounds(0, 0,img, 0);
break;
}
【问题讨论】:
标签: android xml android-layout