为了账号安全,请及时绑定邮箱和手机立即绑定

是什么使按钮背景变白,它不应该是透明的吗?

是什么使按钮背景变白,它不应该是透明的吗?

炎炎设计 2022-05-12 16:25:03
正如您在此处看到的,按钮的背景是透明的。我似乎无法在任一 xml 文件中找到它设置为白色的位置。该按钮被识别为btnCapture代码如下。activity_main.xml<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:id="@+id/container"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity">    <TextureView        android:id="@+id/textureView"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:layout_above="@+id/btnCapture" />    <Button        android:text="@string/capture"        android:id="@+id/btnCapture"        android:layout_width="wrap_content"        android:layout_height="92dp"        android:background="@drawable/rounded_button"        android:layout_alignParentBottom="true"        android:layout_centerInParent="true"        tools:layout_editor_absoluteX="157dp"        tools:layout_editor_absoluteY="202dp" /></RelativeLayout>rounded_button.xml<shape xmlns:android="http://schemas.android.com/apk/res/android"    android:shape="oval">    <stroke android:color="#80000000"    android:width="2dp"></stroke>    <stroke android:color="#D3D3D3"></stroke>    <size android:width="60dp"        android:height="80dp"></size></shape>
查看完整描述

2 回答

?
智慧大石

TA贡献1946条经验 获得超3个赞

您不会更改 Java 代码中与按钮的 UI 相关的任何内容,所以不,这不是因为 Java 代码。它与 XML 相关。

您的按钮背景是一个名为“rounded_button”的可绘制对象,但您尚未发布该可绘制文件的内容。所以我们所能做的就是猜测rounded_button drawable是白色的吗?


查看完整回答
反对 回复 2022-05-12
?
一只甜甜圈

TA贡献1836条经验 获得超5个赞

您可以采取两个快速步骤来使这项工作以您想要的方式进行:


首先,将视图从 Button 更改为 TextView 并应用rounded-button.xml背景。这应该立即起作用。尝试为按钮设置背景有点棘手,如此处所示。


其次,我注意到您的rounded-button.xml文件没有solid元素。实体元素允许您设置布局的背景。出于这个原因,我将您的一个元素更改stroke为一个元素(无论如何solid都不应该有两个元素)。stroke您更新rounded_button.xml的代码如下所示:


PS:不要忘记将您的视图 activity_main.xml 从 Button 更改为 TextView!



<shape 

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="oval">


    <stroke android:color="#80000000"

        android:width="2dp">

    </stroke>


    <solid 

        android:color="#D3D3D3">

    </solid>


    <size 

        android:width="60dp"

        android:height="80dp">

    </size>


</shape>

我希望这有帮助。快乐编码!


查看完整回答
反对 回复 2022-05-12
  • 2 回答
  • 0 关注
  • 96 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号