gpt4 book ai didi

android - 具有完全相同代码的按钮,产生两种不同的样式

转载 作者:行者123 更新时间:2023-11-30 01:25:36 25 4
gpt4 key购买 nike

我有两组不同的按钮,一组在 Activity 中,一组在 ListView 中。它们具有非常相似的代码,但显示两种不同的样式。

标题按钮组代码:

 <Button
android:id="@+id/invoices_1year"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="0.2"
android:onClick="refresh"
android:text="@string/Invoices_1_year" />

而 Listview 的按钮代码是:

<Button
android:id="@+id/invoiceButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="0.25"
android:text="View Pdf" />

@ir2pid 的 Listview 的 Xml:

<ListView
android:id="@+id/InvoiceList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/searchArea" />

我在我的设备上得到的输出:

Image of Whats displayed on device.

我的预期结果是两个按钮组看起来一样。

最佳答案

在drawable文件夹中创建round.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#5e7974" />
<gradient android:angle="-90" android:startColor="#e4d46f" android:endColor="#e4d079" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#c7cf2d" />
<solid android:color="#e9da67"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="3dip" />
<stroke android:width="1dip" android:color="#e7d851" />
<gradient android:angle="-90" android:startColor="#e4d079" android:endColor="#87cf8d" />
</shape>
</item>
</selector>

然后在按钮中添加

android:background="@drawable/round"

关于android - 具有完全相同代码的按钮,产生两种不同的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36466402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com