Android Studio-在运行时更改按钮形状

Android Studio-在运行时更改按钮形状,android,android-layout,runtime,android-button,shapes,Android,Android Layout,Runtime,Android Button,Shapes,我试图在Android Studio中单击按钮,将按钮更改为特定形状 单击按钮后,按钮应类似于: 底部三角形不需要是可点击的。其唯一目的是表明按钮下方有一个打开的碎片 最好的方法是什么?本文介绍如何使用XML形状创建三角形形状 您可以使用此形状相对于按钮(位于按钮下方)放置它。首先将其隐藏,然后单击按钮使其可见。给您: 定义一个ImageButton 请注意,我给了它一个背景“@drawable/tributton” 在可绘图文件夹中定义tributton.xml 请注意,有两种状态

我试图在Android Studio中单击按钮,将按钮更改为特定形状

单击按钮后,按钮应类似于:

底部三角形不需要是可点击的。其唯一目的是表明按钮下方有一个打开的碎片


最好的方法是什么?

本文介绍如何使用XML形状创建三角形形状

您可以使用此形状相对于按钮(位于按钮下方)放置它。首先将其隐藏,然后单击按钮使其可见。

给您:

定义一个ImageButton

请注意,我给了它一个背景“@drawable/tributton”

在可绘图文件夹中定义tributton.xml

请注意,有两种状态,一种是按下按钮,另一种是其他状态。您可以根据需要更改状态

在drawable文件夹中创建my_path.xml

在drawable文件夹中创建my_normal_path.xml

结果如下:

正常的

点击

我建议使用。。xml中的选择器。并在选择后使用两个按钮button@NitinKarande你能举个例子吗?你核对过我的答案了吗?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main3"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ul_ts.emvsdktester.drawabletraining.Main3Activity">

    <ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tributton" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/my_path" android:state_pressed="true" />
    <item android:drawable="@drawable/my_normal_path" />
</selector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100">

    <path
        android:fillColor="#32c2b6"
        android:pathData="M0 0 L50 0 L50 50 L30 50 L25 60 L20 50 L0 50 Z"
        android:strokeColor="#9a1616" />

</vector>
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="100dp"
    android:height="100dp"
    android:viewportHeight="100"
    android:viewportWidth="100">

    <path
        android:fillColor="#d0ce5b"
        android:pathData="M0 0 L50 0 L50 50 L0 50 Z"
        android:strokeColor="#000000" />

</vector>