簡體   English   中英

Android 按鈕 - 將矩形放在其他矩形中

[英]Android button - Put rectangle in other rectangle

我想為一個按鈕做一個自定義設計,像這樣(示例):

在此處輸入圖片說明

我知道如何編輯默認設計(帶形狀),我成功制作了一個矩形,但未能在同一形狀上添加第二個矩形。

我該怎么做 ?

你可以這樣做

在, main_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout 
        android:onclick="onclickbtn"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:background="@android:color/darker_gray">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:textSize="18sp"
            android:layout_centerInParent="true"
            android:textColor="@android:color/white"
            android:text="My Text Button"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_alignParentEnd="true"
            android:textColor="@android:color/white"
            android:text="new"
            android:background="@android:color/holo_blue_light"/>

    </RelativeLayout>
</RelativeLayout>

Onclick In, Main_activity.java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void onclickbtn(View view) {
        Toast.makeText(this, "Button Clicked", Toast.LENGTH_SHORT).show();
    }

}

輸出: 輸出

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM