【发布时间】:2016-05-25 18:55:57
【问题描述】:
我有以下布局:
<LinearLayout
android:id="@+id/myButton"
android:layout_width="@dimen/logo_radius"
android:layout_height="match_parent"
android:background="@drawable/myShape">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/driver_half"/>
</LinearLayout>
还有以下myShapedrawable:
<selector>
<item><shape android:shape="oval">
<stroke android:color="@android:color/black" android:width="4dp"/>
<solid android:color="@android:color/white" />
</shape></item>
</selector>
我应用了以下过滤器:
myButton.getBackground().setColorFilter( orange, PorterDuff.Mode.ADD );
结果看起来是这样的:
然后我将 myShape 更改为圆角矩形:
<selector>
<item>
<shape
android:shape="rectangle">
<corners android:bottomLeftRadius="@dimen/logo_radius" android:bottomRightRadius="2dp" android:topLeftRadius="@dimen/logo_radius" android:topRightRadius="2dp"/>
<stroke
android:width="4dp"
android:color="@android:color/black"/>
<solid android:color="@android:color/white"/>
</shape>
</item>
</selector>
结果如下:
左边部分没有应用过滤器,右边部分有过滤器。
我想得到什么:
我应该怎么做才能使用 Porter-Duff 过滤器正确地将边框涂成橙色?还有其他选择吗?
【问题讨论】:
-
按下时会变成橙色吗?
-
不,边框应始终保持橙色。
-
为什么不直接使用橙色而不是@android:color/black?
-
因为它必须像皮肤一样以编程方式设置
-
也许吧。我想将形状保留在 xml 中。我最初的问题是,为什么
oval有效,而rectangle无效?
标签: android shape porter-duff