猿问

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

正如您在此处看到的,按钮的背景是透明的。我似乎无法在任一 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>


炎炎设计
浏览 97回答 2
2回答

智慧大石

您不会更改 Java 代码中与按钮的 UI 相关的任何内容,所以不,这不是因为 Java 代码。它与 XML 相关。您的按钮背景是一个名为“rounded_button”的可绘制对象,但您尚未发布该可绘制文件的内容。所以我们所能做的就是猜测rounded_button drawable是白色的吗?

一只甜甜圈

您可以采取两个快速步骤来使这项工作以您想要的方式进行:首先,将视图从 Button 更改为 TextView 并应用rounded-button.xml背景。这应该立即起作用。尝试为按钮设置背景有点棘手,如此处所示。其次,我注意到您的rounded-button.xml文件没有solid元素。实体元素允许您设置布局的背景。出于这个原因,我将您的一个元素更改stroke为一个元素(无论如何solid都不应该有两个元素)。stroke您更新rounded_button.xml的代码如下所示:PS:不要忘记将您的视图 activity_main.xml 从 Button 更改为 TextView!<shape&nbsp;&nbsp; &nbsp; xmlns:android="http://schemas.android.com/apk/res/android"&nbsp; &nbsp; android:shape="oval">&nbsp; &nbsp; <stroke android:color="#80000000"&nbsp; &nbsp; &nbsp; &nbsp; android:width="2dp">&nbsp; &nbsp; </stroke>&nbsp; &nbsp; <solid&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; android:color="#D3D3D3">&nbsp; &nbsp; </solid>&nbsp; &nbsp; <size&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; android:width="60dp"&nbsp; &nbsp; &nbsp; &nbsp; android:height="80dp">&nbsp; &nbsp; </size></shape>我希望这有帮助。快乐编码!
随时随地看视频慕课网APP

相关分类

Java
我要回答