在 Android 中设计一个按钮

Design a button in Android

我正在设计一个Androidactivity,但这是第一个

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

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

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

有更专业的人告诉我怎么做吗?

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

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"/>

另一个没那么简单:/

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

在您提供的情况下,您可以愉快地拥有类似的东西:

LinearLayout
    TextView
    ImageButton
    TextView
    ImageButton

第一个 ImageButton 可以是简单的橙色背景色,也​​可以使用 crafted XML drawable.

变得更复杂

第二个 ImageButton 需要是 ninepatch drawable

在可绘制文件夹中使用您的按钮设计创建一个 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>

然后在你的activity布局中,将按钮背景设置为设计;

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

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

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

how to create custom view