【问题标题】:Android Button CustomizationAndroid 按钮自定义
【发布时间】:2014-01-27 20:56:22
【问题描述】:

请问如何将icon on my button 像下图一样输入?

还有我在哪里可以找到资源或sample resources of buttons 这样的?

【问题讨论】:

标签: android android-layout user-interface interface


【解决方案1】:

您需要将可绘制对象设置在 Button 的左侧。通过xmlprogrammatically

【讨论】:

  • 你有样品吗?
  • 样本遍布网络,先生。
  • 由于您这边没有可添加的代码,我将坚持使用@Nfear 的答案。
【解决方案2】:

要么创建一个按钮并设置一个复合可绘制对象,要么创建一个 ImageButton。

【讨论】:

    【解决方案3】:
    <TextView android:id="@+id/login_with_facebook"
              android:layout_width="100dp"
              android:height="48dp"
              android:text="FACEBOOK"
              android:gravity="center"
              android:drawableLeft="@drawable/facebook_icon_48_x_48"
              android:clickable="true"/>
    

    【讨论】:

    • 文本视图?我要问的是按钮先生。谢谢。
    • 先生,如您所见,它是可点击的,如果这个按钮或文本视图用户不会看到任何区别
    【解决方案4】:
    <Button android:drawableLeft="@drawable/image"
             android:text="facebook"/>
    

    如果你想要图像和文本之间的空间,然后给drawablePadding Like:

    <Button android:drawableLeft="@drawable/image"
             android:text="facebook"
             android:drawablePadding="10dp"/>
    

    【讨论】:

      【解决方案5】:

      使用RelativeLayout 可以轻松完成。我给你找了sn-p,

          <RelativeLayout 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerHorizontal="true">
      
              <Button 
                  android:id="@+id/fb_logo_button"
                  android:text=""
                  android:background="fb_logo"
                  android:layout_height="match_parent"
                  android:layout_width="match_parent"/>
      
              <Button 
                  android:layout_toRightOf="@id/fb_logo_button"
                  android:id="@+id/fb_text_button"
                  android:text="Facebook"
                  android:textAlignment="center"
                  android:background="@android:color/holo_blue_bright"
                  android:layout_height="match_parent"
                  android:layout_width="match_parent"/>
      
          </RelativeLayout>
      

      这将确保无论您的图像是用于各自的DPIs,它都会将此布局对齐到水平居中。在此布局中,徽标将始终位于文本的左侧,如图所示。

      这适用于您的父母也是RelativeLayout 的情况。如果您将LinearLayout 作为父级,则在上面的RelativeLayout 标签将android:layout_centerHorizontal="true" 更改为android:layout_gravity="center_horizontal"

      由于我不在家,我无法在 Eclipse 中对其进行测试。试试这个,让我知道。谢谢。

      【讨论】:

        猜你喜欢
        • 2016-08-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-12-01
        • 2016-08-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多