Android - 一侧边框 ImageButton

标签 android border imagebutton

我试图仅在一侧绘制边框 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/

相关文章:

java - Android:取出下一张具有钉书钉效果的扑克牌

android - 根据屏幕设备大小调整图像按钮大小

java - Android,在DIALOG中点击 "ok"后重新加载或刷新当前 fragment

java - 如何在后台线程中使用 HttpPost 执行 MultipartEntity?

windows - WP7 去除黑边

css - 如何摆脱 Chrome 和 Firefox 中的文本表单边框?

html - 火狐错误?在 img 上得到不需要的(和未编码的)笔划(在其他浏览器上工作)

c# - 按钮自动调整为 0px x 0px

android - 如何在 Flutter 中模拟 Android 的 showAsAction ="ifRoom"?

android - 还有其他方法可以为 Android 测试模拟 SharedPreferences 吗?