【问题标题】:Design a button in Android在 Android 中设计一个按钮
【发布时间】:2015-07-06 03:03:17
【问题描述】:

我正在设计一个 Android Activity,但它是第一个。

我在 XML/JAVA 方面有一些经验。

我想创建像照片中那样的注销和阅读按钮。

但是我没有做这种事情的经验。

谁能告诉我如何做到这一点?

【问题讨论】:

  • 我不太明白你想做什么......你能更好地解释你的问题吗?如果你有这方面的照片,那就更好了
  • 照片在问题中。我想创建像照片中那样的 Android 按钮。
  • 我认为你应该使用材料设计或安卓设计来做到这一点,我认为你必须在 web 视图中使用 web 技术,但我不认为这种方式是好的练习,祝你好运!

标签: android eclipse android-layout button android-view


【解决方案1】:

这就是我创建注销按钮的方式

logout_button.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">

    <solid android:color="#FFFFFD"/>
    <corners android:radius="15dp"/>
    <stroke
        android:width="1dp"
        android:color="#5C88A1"/>

</shape>

以及布局中的按钮

<Button
    android:id="@+id/btnLogout"
    android:layout_width="150dp"
    android:layout_height="30dp"
    android:background="@drawable/logout_button"
    android:gravity="center"
    android:text="logout"
    android:textColor="#7E9196"
    android:textSize="15sp"/>

另一个没那么简单:/

【讨论】:

    【解决方案2】:

    您需要将每个部分分解为组件。

    在您提供的情况下,您可以很高兴地拥有类似的东西:

    LinearLayout
        TextView
        ImageButton
        TextView
        ImageButton
    

    第一个 ImageButton 可以是简单的橙色背景颜色,或者您可以使用 crafted XML drawable 变得更复杂。

    第二个 ImageButton 必须是 ninepatch drawable

    【讨论】:

      【解决方案3】:

      在可绘制文件夹中使用您的按钮设计创建一个 XML,例如; okButtonDesign.xml

      <?xml version="1.0" encoding="UTF-8"?>
      <shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle" >
      
       <gradient
          android:angle="180"
          android:endColor="#D8D8D8"
          android:startColor="#F7D358" />
      
       <corners android:radius="10px" />
      
       <stroke
          android:width="2px"
          android:color="#000000" />
      
      </shape>
      

      然后在您的活动布局中,将按钮背景设置为设计;

      <Button
       android:id="@+id/btnloginok"
       android:background="@drawable/okButtonDesign"
       android:gravity="center"
       android:text="@string/logonbuttontext"
       android:textColor="#A4A4A4"android:textSize="@dimen/loginTextSize" />
      

      【讨论】:

        【解决方案4】:

        对于注销按钮,请检查此答案:rounded button

        按钮读取:有两种方式。一种是创建 9-patch,但你必须在 gfx 程序中创建它。 第二种方法是用代码编写这个按钮,你可以从这里学习:

        how to create custom view

        【讨论】:

          猜你喜欢
          • 2014-08-20
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-08
          • 1970-01-01
          • 2016-06-28
          • 2015-01-04
          相关资源
          最近更新 更多