我试图仅在一侧绘制边框 ImageButton
对象,
就像CSS中的:border-left: 2px solid black;
。
有什么方法可以仅通过样式来做到这一点吗? (不在它们之间插入空白 View )
谢谢!
编辑:
我用了<selector>
带有 ImageButton
的标签.
最佳答案
经过大量搜索,我找到了方法。
创建包含边框样式的 xml 文件 (border_style.xml):
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
<!-- The border color -->
<solid android:color="#000" />
</shape>
</item>
<item android:left="1dp">
<shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle">
<!-- The fill color-->
</shape>
</item>
</layer-list>
然后在选择器中,你可以这样写:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<!-- Press Event -->
</item>
<item android:state_focused="true">
<!-- Focuse Event -->
</item>
<item android:drawable="@drawable/border_style.xml" />
</selector>
关于Android - 一侧边框 ImageButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12989220/