android图片填充颜色
① android 里用shape画圆,怎么填充颜色
背景色那里改一下就行了
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<!--背景色-->
<solid android:color="@color/redbg"/>
<!-- 边框色 -->
<stroke android:width="1dp"
android:color="#ee5859"/>
<size android:width="95dp"
android:height="95dp"/>
</shape>
② android 里用shape画圆,怎么填充颜色
增加一个填充就好了
<!-- 填充 -->
<solid
android:color="@android:color/white"/><!-- 填充的颜色 -->
③ android设置控件样式(边框颜色,圆角)和图片样式(圆角)
本文链接:https://blog.csdn.net/weixin_37577039/article/details/79090433
```
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorAccent" />
<!-- 这里是设置为四周 也可以单独设置某个位置为圆角-->
<corners android:topLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomRightRadius="5dp"
android:bottomLeftRadius="5dp"/>
<stroke android:width="1dp" android:color="#000000" />
</shape
```
```
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 边框颜色值 -->
<item>
<shape>
<solid android:color="#3bbaff" />
</shape>
</item>
<!--这个是按钮边框设置为四周 并且宽度为1-->
<item
android:right="1dp"
android:left="1dp"
android:top="1dp"
android:bottom="1dp">
<shape>
<!--这个是背景颜色-->
<solid android:color="#ffffff" />
<!--这个是按钮中的字体与按钮内的四周边距-->
<padding android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
</item>
</layer-list>
```
使用:
```android:background="@drawable/button_edge"```
```
<?xml version="1.0" encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="#FFFFFF" />
<!-- android:radius 弧形的半径 -->
<!-- 设置按钮的四个角为弧形 -->
<corners
android:radius="5dip" />
<!--也可单独设置-->
<!-- <corners -->
<!-- android:topLeftRadius="10dp"-->
<!-- android:topRightRadius="10dp"-->
<!-- android:bottomRightRadius="10dp"-->
<!-- android:bottomLeftRadius="10dp"-->
<!-- /> -->
**设置文字padding**
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp"
/>
</shape>
```
```
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
```
使用:
```
android:background="@drawable/image_circle"
```
```
Glide.with(MainActivity.this).load(croppedUri)
.transform(new GlideRectRound(MainActivity.this,6)).into(headIcon);
```
```
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.Log;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
/**
* Created by SiHao on 2018/3/3.
* Glide 的 圆角 图片 工具类
*/
public class GlideRectRound extends BitmapTransformation {
private static float radius = 0f;
// 构造方法1 无传入圆角度数 设置默认值为5
public GlideRectRound(Context context) {
this(context, 5);
}
// 构造方法2 传入圆角度数
public GlideRectRound(Context context, int dp) {
super(context);
// 设置圆角度数
radius = Resources.getSystem().getDisplayMetrics().density * dp;
}
// 重写该方法 返回修改后的Bitmap
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return rectRoundCrop(pool,toTransform);
}
@Override
public String getId() {
Log.e("getID",getClass().getName() + Math.round(radius));
return getClass().getName() + Math.round(radius); // 四舍五入
}
private Bitmap rectRoundCrop(BitmapPool pool, Bitmap source){
if (source == null) return null;
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); // ARGB_4444——代表4x4位ARGB位图,ARGB_8888——代表4x8位ARGB位图
if (result == null) {
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
// setShader 对图像进行渲染
// 子类之一 BitmapShader设置Bitmap的变换 TileMode 有CLAMP (取bitmap边缘的最后一个像素进行扩展),REPEAT(水平地重复整张bitmap)
//MIRROR(和REPEAT类似,但是每次重复的时候,将bitmap进行翻转)
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true); // 抗锯齿
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());
canvas.drawRoundRect(rectF, radius, radius, paint);
return result;
}
}
```
圆角:
```
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
/**
* Created by SiHao on 2018/3/3.
* Glide圆形图片工具类
*/
public class GlideCircleBitmap extends BitmapTransformation{
public GlideCircleBitmap(Context context) {
super(context);
}
// 重写该方法 返回修改后的Bitmap
@Override
protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {
return circleCrop(pool, toTransform);
}
@Override
public String getId() {
return getClass().getName();
}
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
if (source == null) return null;
// 边长取长宽最小值
int size = Math.min(source.getWidth(), source.getHeight());
int x = (source.getWidth() - size) / 2;
int y = (source.getHeight() - size) / 2;
// TODO this could be acquired from the pool too
Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);
Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);// ARGB_4444——代表4x4位ARGB位图,ARGB_8888——代表4x8位ARGB位图
if (result == null) {
result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
}
Canvas canvas = new Canvas(result);
Paint paint = new Paint();
// setShader 对图像进行渲染
// 子类之一 BitmapShader设置Bitmap的变换 TileMode 有CLAMP (取bitmap边缘的最后一个像素进行扩展),REPEAT(水平地重复整张bitmap)
//MIRROR(和REPEAT类似,但是每次重复的时候,将bitmap进行翻转)
paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
paint.setAntiAlias(true);// 抗锯齿
// 半径取 size的一半
float r = size / 2f;
canvas.drawCircle(r, r, r, paint);
return result;
}
}
```
```
URL url = new URL(String类型的字符串); //将String类型的字符串转换为URL格式
holder.UserImage.setImageBitmap(BitmapFactory.decodeStream(url.openStream()));
```
```
//得到资源文件的BitMap
Bitmap image= BitmapFactory.decodeResource(getResources(),R.drawable.dog);
//创建RoundedBitmapDrawable对象
RoundedBitmapDrawable roundImg =RoundedBitmapDrawableFactory.create(getResources(),image);
//抗锯齿
roundImg.setAntiAlias(true);
//设置圆角半径
roundImg.setCornerRadius(30);
//设置显示图片
imageView.setImageDrawable(roundImg);
```
```
//如果是圆的时候,我们应该把bitmap图片进行剪切成正方形, 然后再设置圆角半径为正方形边长的一半即可
Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.dog);
Bitmap bitmap = null;
//将长方形图片裁剪成正方形图片
if (image.getWidth() == image.getHeight()) {
bitmap = Bitmap.createBitmap(image, image.getWidth() / 2 - image.getHeight() / 2, 0, image.getHeight(), image.getHeight());
} else {
bitmap = Bitmap.createBitmap(image, 0, image.getHeight() / 2 - image.getWidth() / 2, image.getWidth(), image.getWidth());
}
RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
//圆角半径为正方形边长的一半
roundedBitmapDrawable.setCornerRadius(bitmap.getWidth() / 2);
//抗锯齿
roundedBitmapDrawable.setAntiAlias(true);
imageView.setImageDrawable(roundedBitmapDrawable);
```
④ android 里用shape画圆,怎么填充颜色
<shape>节点下的<solid>节点是用来设置填充颜色的。
使用方法只需要添加代码<solid android:color= "填充色" />
例如<solid android:color= "@color/red" />或者<solid android:color= "#ffff00" />
⑤ android 里用shape画圆,怎么填充颜色
用圆形选区(M)按住ALT+SHIFT键拖出一个圆形。然后将前景色调至图片的颜色(可以用吸管吸色)。填充颜色(ALT+
⑥ android 里用shape画圆,怎么填充颜色
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!-- 控件里面的颜色,如果是EditText的话里面设置#ffffff 或者自己喜欢的颜色-->
<solid android:color="@color/new_blue"/>
<!-- 圆角度-->
<corners android:radius="2dp"/>
<!-- 控件外面边框的颜色和宽度 如果选择不要边框的去掉这个就是了-->
<stroke android:width="1px" android:color="@color/blue"/>
</shape>
⑦ android 里用shape画圆,怎么填充颜色
android 用shape画圆,使用<solid android:color="#f00" />(#f00表示填充的颜色),该属性来填充颜色,在Android studio按照如下步骤创建圆点并添加颜色属性。
1、在使用Android studio创建的Android项目中,在drawable中创建一个空白文件,如下图:
⑧ android 里用shape画圆,怎么填充颜色
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="
>
<stroke android:width="1dp" android:color="#ff0000" /> <!--描边-->
<solid android:color="#ff0000" /><!--填充-->
</shape>
⑨ android 里用shape画圆,怎么填充颜色
Android里面使用shape设置控件的外形,例如一些圆角、填充的背景颜色、以及一些渐变的效果等,所以设置填充颜色,可通过设置shape.xml文件里的如下属性:
<solidandroid:color="@color/common_red"/>
将shape文件放到android的button、textview组件上,就可以有填充背景颜色的效果,完整的代码如下:
1.shape.xml
<?xmlversion="1.0"encoding="UTF-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval"
android:useLevel="false">
<solidandroid:color="@color/common_red"/>
<padding
android:left="2dp"
android:top="1dp"
android:right="2dp"
android:bottom="1dp"/>
<solid
android:color="@color/common_red"/>
<stroke
android:width="1dp"
android:color="@android:color/white"/>
<sizeandroid:width="15dp"
android:height="15dp"/>
</shape>
2.把以上代码添加到drawable里面、通过background引用就可以了
<TextView
android:id="@id/message_category_unread_count"
style="@style/comm_text_style_14_aaaaaa"
android:layout_marginLeft="70dp"
android:layout_marginTop="5dp"
android:background="@drawable/shape"
android:gravity="center"
android:textSize="@dimen/text_size_comment_20"
android:text="7"
android:textColor="@android:color/white"/>
效果如下图:
⑩ android 里用shape画圆,怎么填充颜色
为你其中提供一种解决方案:
android;msg_new_counter"22"
android;
android;20dp"
android;>.com/apk/res/android"0dp" android;
android;
android;
android;utf-8".android;/://schemas;TextView
android; /:width="shape xmlns;top|center_horizontal".com/apk/res/android" target="_blank">http.0":background="3dp":text=":layout_height="bold" android;false"
android:textColor="ring"solid android;>
android;bg_have_msg".android://schemas;wrap_content":layout_width=";2":layout_marginTop="8sp":shape="stroke android; encoding="1;
android;3dp"
android;
<:id="
android;
<
2;#ffffff":useLevel="wrap_content"?xml version=":innerRadiusRatio=":textSize="#ff0000">@+id/1"
<
android;
android:color=":layout_marginLeft="#ff0000"
android:thicknessRatio=":color=".资源文件
<?>:textStyle="/ /:innerRadius=":padding=":android=">
<
在android studio的布局预览里显示正常(红底白字的圆):thickness="
android布局文件
<1dp"