是什么使按钮背景变成白色,难道不是透明的吗?

时间:2019-01-19 23:51:59

标签: java android xml android-studio

如您在此处看到的,按钮的背景是透明的。我似乎找不到在两个xml文件中将其设置为白色的位置。该按钮被标识为btnCapture,代码如下。

enter image description here

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 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

您可以按照以下两个快速步骤来完成此工作:

首先,将视图从“按钮”更改为“文本视图”,并应用您的 <xp:div id="chartContracts" style="width: 500px; height: 300px;padding- top:8px"></xp:div> <xp:scriptBlock id="scriptBlock2"> <xp:this.value><![CDATA[ require([ "dojox/charting/Chart", "dojox/charting/plot2d/Columns", "dojox/charting/themes/Minty", "dojox/charting/action2d/Tooltip", "dojox/charting/axis2d/Default", "dojo/number", "dojo/currency", "dojo/domReady!" ], function(Chart,Columns,Minty,Tooltip) { var chart1 = new Chart("#{id:chartContracts}"); chart1.addPlot("default",{type: Columns,gap:2} ); var tip = new Tooltip(chart1,"default"); // Add axes var varNames = #{contractBean.axisXAxis}; var funcLabels = function(text) { return varNames[text]; } chart1.addAxis("y", {vertical:true,}); chart1.addAxis("x", {labelFunc:funcLabels, font:"normal normal normal 8pt Tahoma",minorTicks:true,rotation:-90, maxLabelCharCount:11, }); chart1.setTheme(Minty); var data = #{contractBean.chartContractsData}; for (var key in data) { chart1.addSeries(key, data[key]); }; chart1.render(); });]]></xp:this.value> </xp:scriptBlock> 背景。这应该立即起作用。尝试将背景设置为按钮here有点棘手。

其次,我注意到您的public void setChartContracts(){ JsonJavaArray jjaXAxis = new JsonJavaArray(); JsonJavaObject jjoContracts = new JsonJavaObject(); jjaXAxis.add(""); ArrayList<Object> seriesContracts=new ArrayList<Object>(); Iterator<Contract> it = allContracts.iterator(); while(it.hasNext()){ Contract entry = (Contract) it.next(); Double actTO = entry.getActualTO(); if(actTO >999.99){ //We only want contracts with a value greater than 999.99 HashMap<String,Object> mapContracts = new HashMap<String,Object>(); int actProfit = entry.getActualProfit().intValue(); mapContracts.put("y",actProfit); String col = actProfit<0.00 ? "#ff1a1a" : "#00cc66"; //Colour the columns, green positive red negative. mapContracts.put("fill",col); mapContracts.put("stroke",""); mapContracts.put("tooltip","£"+actProfit); seriesContracts.add(mapContracts); jjaXAxis.add(entry.getCustomerName()); } } jjoContracts.put("contracts",seriesContracts); chartContractsData = jjoContracts.toString(); System.out.println(chartContractsData); axisXAxis = jjaXAxis.toString(); } 文件没有rounded-button.xml元素。实体元素允许您设置布局的背景。因此,我将您的rounded-button.xml元素之一更改为solid元素(无论如何都不应有两个stroke元素)。您更新后的solid代码如下所示:

PS:别忘了将您的视图改变 stroke 从“按钮”更改为“ TextView”!

rounded_button.xml

我希望这会有所帮助。快活的编码!