答案 0 :(得分:8)
我为此创建了一个矢量drawable:
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="220dp" android:height="220dp" android:viewportHeight="230.0" android:viewportWidth="230.0">
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M165,5C178.2,5 198.2,5 225,5L225,30.79L225,65"
android:strokeColor="@color/qr_code_reader_square" android:strokeWidth="10"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M5,65C5,51.8 5,31.8 5,5L30.79,5L65,5"
android:strokeColor="@color/qr_code_reader_square" android:strokeWidth="10"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M165,225C178.2,225 198.2,225 225,225L225,199.21L225,165"
android:strokeColor="@color/qr_code_reader_square" android:strokeWidth="10"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M5,165C5,178.2 5,198.2 5,225L30.79,225L65,225"
android:strokeColor="@color/qr_code_reader_square" android:strokeWidth="10"/>
</vector>
您可以将其res/drawable
保存为qr_code_reader_square.xml
,然后在您的布局中使用它,如下所示:
<FrameLayout
android:layout_width="250dp"
android:layout_height="250dp"
android:background="@drawable/qr_code_reader_square"/>
您还必须在res/values/colors.xml
中设置颜色:
<color name="qr_code_reader_square">#FFFFFFFF</color>
答案 1 :(得分:2)
使用下面的可绘制文件并设置QR码的背景: -
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape android:shape="rectangle">
<stroke android:color="@color/black" android:width="5dp"/>
<solid android:color="@color/white"/>
</shape>
</item>
<item android:left="20dp" android:right="20dp">
<shape android:shape="rectangle">
<solid android:color="@color/white"/>
</shape>
</item>
<item android:top="20dp" android:bottom="20dp">
<shape android:shape="rectangle">
<solid android:color="@color/white"/>
</shape>
</item>
</layer-list>
答案 2 :(得分:0)
我缩短了边缘。现在看起来好多了。
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:width="200dp" android:height="200dp" android:viewportHeight="230.0" android:viewportWidth="230.0">
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M200,5C197.1,5 198,5 225,5L225,30.79L225,6"
android:strokeColor="@color/colorWhite" android:strokeWidth="2"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M5,15C5,51.8 5,5 5,5L10.19,5L30,5"
android:strokeColor="@color/colorWhite" android:strokeWidth="2"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M200,225C200,225 200,225 225,225L225,200.21L225,200"
android:strokeColor="@color/colorWhite" android:strokeWidth="2"/>
<path android:fillColor="#00000000" android:fillType="evenOdd"
android:pathData="M5,200C5,200 5,210 5,225L30.90,225L7,225"
android:strokeColor="@color/colorWhite" android:strokeWidth="2"/>
</vector>
您应该检查一下: