有没有办法创造EditText圆角?
我试图在android中创建一个圆角边的视图.到目前为止我找到的解决方案是定义一个带圆角的形状,并将其用作该视图的背景.
这就是我所做的,定义一个drawable,如下所示
<padding
android:top="2dp"
android:bottom="2dp"/>
<corners android:bottomRightRadius="20dp"
android:bottomLeftRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp"/>
Run Code Online (Sandbox Code Playgroud)
现在我用它作为我的布局的背景如下
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:clipChildren="true"
android:background="@drawable/rounded_corner">
Run Code Online (Sandbox Code Playgroud)
这很好用,我可以看到视图有圆角.
但我的布局中有许多其他子视图说一个ImageView或一个MapView.当我在上面的布局中放置一个ImageView时,图像的角不会被剪裁/裁剪,而是显示为满.
我已经看到了其他解决方法,使它像这里解释的那样工作.
但有没有一种方法可以为视图设置圆角,并且所有子视图都包含在具有圆角的主视图中?
谢谢.
如果有人可以帮我使用如何使用shape drawable作为我的视图的背景xml,我真的很感激.
这就是我的尝试:但我从未得到过这种颜色.Android总是在白色背景上给我黑色文字,无论我放置什么颜色属性.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dip" android:color="#FBBB" />
<solid android:color="#6000"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
我试过了,不行
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:color="#6000>
</shape>
Run Code Online (Sandbox Code Playgroud)
我试过了,不行
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:background="#6000>
</shape>
Run Code Online (Sandbox Code Playgroud)
我谷歌这是我发现尝试的有限结果.
我一直致力于生成二维码并将其显示在屏幕上。现在我可以使用 Zxing 库生成它,该库为我提供了一个 BitMatrix,该 BitMatrix 返回 x 和 y 值的布尔值(如果该坐标需要为黑色或白色)。现在我可以使用以下代码成功生成并显示二维码:
String charset = "UTF-8";
Map<EncodeHintType, ErrorCorrectionLevel> hintMap = new HashMap<>();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
BitMatrix matrix = new QRCodeWriter().encode(new String(url.getBytes(charset), charset), BarcodeFormat.QR_CODE, (int) context.getResources().getDimension(R.dimen.qr_square), (int) context.getResources().getDimension(R.dimen.qr_square), hintMap);
Bitmap bitmap = Bitmap.createBitmap(matrix.getWidth(), matrix.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint();
paint.setColor(Color.BLACK);
for (int y = 0; y < matrix.getHeight(); y++) {
for (int x = 0; x < matrix.getWidth(); x++) {
if (!overlayRect.contains(x, y))
canvas.drawPoint(x, y, paint);
}
} …Run Code Online (Sandbox Code Playgroud)