【问题标题】:Android Button/TextView stylingAndroid Button/TextView 样式
【发布时间】:2016-07-02 16:11:09
【问题描述】:

我想要一个button like this。 它基本上是一个文本:NEXT,右侧有一个 Chevron

我已经尝试了一个带有透明背景和android:drawableRight 的按钮,但是drawable 的填充看起来很奇怪。

我怎样才能获得想要的外观?

到目前为止我所拥有的:

<Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Next"
            android:textColor="@color/colorAccent"
            android:drawableRight="@drawable/chevron_right"
            android:background="#00000000"/>

/很抱歉发布链接而不是直接发布照片,但我的声誉不够高。/

【问题讨论】:

  • 分享你目前拥有的代码
  • @GennadiiSaprykin 添加了它。

标签: android android-layout material-design android-button


【解决方案1】:

您可以使用包含ImageButtonFrameLayout/RelativeLayout 和水平的LinearLayout/RelativeLayout 来执行此操作,其中包含文本和右对齐的人字形图像。像这样的:

  <FrameLayout
        android:id="@+id/fl_btn_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageButton
            android:id="@+id/imbtn_btn_bg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/white_drawable" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical">

            <TextView
                android:id="@+id/tv_btn_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginRight="10dp"
                android:gravity="center_horizontal"
                android:text="@string/next" />

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_toRightOf="@id/tv_btn_text"
                android:src="@drawable/chevron" />
        </RelativeLayout>
    </FrameLayout>

这个例子来自我的应用,可能你需要修改它。

【讨论】:

  • 谢谢你的回答,我知道这样是可以的,但我觉得有更好的办法。
【解决方案2】:

您是否尝试过使用 dp 的负值设置 chevron 视图和边框之间的空间。 去年我也遇到过类似的问题,正负dp的适当组合解决了它

【讨论】:

  • 好主意,部分有效,因为整个按钮大小保持不变。
  • 哎呀错过了那部分。 Ohkie 那么我们现在缺少哪一部分
【解决方案3】:

您可以使用android:drawablePadding="8dp" 设置文本和drawable 之间的填充。

【讨论】:

  • 是的,可以,但如果设置为 0dp,则填充仍然相对较多。这就是我所说的“drawable 的填充看起来很奇怪”。
  • 也可以添加负边距。
【解决方案4】:

我不确定你想要什么,但我会这样做你附加的按钮

<RelativeLayout
    android:layout_width="80dp"     
    android:background="@color/colorAccent"
    android:layout_height="40dp">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_centerInParent="true"

        android:layout_height="wrap_content">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="NEXT"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:src="@android:drawable/arrow_up_float"/>
    </LinearLayout>
</RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-18
    • 2014-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多