导航:首页 > 操作系统 > android按钮设置边框颜色

android按钮设置边框颜色

发布时间:2022-12-23 06:04:55

㈠ 怎么给android 设置边框

Android表格布局本身没有边框,不过可以通过背景色的设置可以实现表格边框的显示。
首先可以设置TableRow的背景色,然后设置内容的背景色。根据它们的颜色差就出现了边框。只要微调Content与TableRow的margin和pading属性就可以了!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >

<include layout="@layout/titlebar_home" />

<TableLayout
android:id="@+id/table1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:padding="6.5dip" >

<TableRow
android:background="@color/jiemianbiankuang"
android:orientation="horizontal"
android:paddingLeft="0.5dip"
android:paddingRight="0.5dip"
android:paddingTop="1dip" >

<ImageButton
android:id="@+id/imageViewMSG"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:contentDescription="@string/messagecenter"
android:src="@drawable/msg" />

<ImageButton
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/book" />

<ImageButton
android:id="@+id/imageView2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/maozi" />
</TableRow>

<TableRow
android:background="@color/jiemianbiankuang"
android:orientation="horizontal"
android:paddingLeft="0.5dip"
android:paddingRight="0.5dip"
android:paddingTop="0dip" >

<ImageButton
android:id="@+id/imageView4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/earth" />

<ImageButton
android:id="@+id/imageView5"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/unno" />

<ImageButton
android:id="@+id/imageView6"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_vertical"
android:layout_marginBottom="0.5dip"
android:layout_marginLeft="0.5dip"
android:background="@color/white"
android:src="@drawable/zuoye" />
</TableRow>
</TableLayout>

</RelativeLayout>

㈡ android开发,EditText的边框的颜色怎么设置

EditText的自带属性里没有设置边框颜色的 有俩种方式可以达到效果 一种是网上比较推崇的用图作背景,另一种则是自绘 图作背景的: 首先重新定义一个style。在values文件夹下新建一个style.xml文件: @drawable/my_edittext 接下来在drawable里添...

㈢ 怎么给android 设置边框

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑。Android在开发过程中,很多情况下需要我们在TextView上面添加一个边框,但是TextView本身不支持边框,这里介绍几种设置边框的方法,可以供大家参考:

㈣ 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的设计支持库FAB按钮边框颜色

我是在一个不错的开源的FloatingActionButton库基础上实现的,链接github开源库 参考图片的标记和代码里的注释。代码如下:
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/fab_meau"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
fab:fab_addButtonColorNormal="@color/theme_color" //修改meau按钮的背景色
fab:fab_addButtonColorPressed="@color/fab_pressed_color" //meau按钮按下的颜色
fab:fab_addButtonPlusIconColor="@color/white" //meau中间 "+" 的颜色
fab:fab_labelStyle="@style/fab_labels_style" //title样式,可以修改title的颜色和背景
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"

㈥ Android CheckBox 改变边框和填充色

如果我们想要改变边框和填充色,同时也保存material design动画效果

需要新建一个 style :

设置checkbox 时如下

ps:如果 style 不起作用

修改为如下

㈦ 怎么给android 设置边框

使用shape,
<solid android:color="#FF6D00"/>(控件的填充颜色)
<stroke android:width="2dp"
android:color="#FF6D00"/>(边框的宽度以及颜色)
<corners android:radius="3dp"/>(边框的角的弧度)

㈧ 怎么给android 设置边框

1.首先在res目录下新建一个xml文件,类型选择drawable,将自动生一个一个drawable文件(我用的sdk是android 4.1),并生成一个xml文件,在其中写入以下代码:

[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

<solid android:color="#FFFFFF" />

<stroke
android:width="0.01dp"
android:color="#FFFFFF" />

<padding
android:bottom="1dp"
android:left="0.5dp"
android:right="0.5dp"
android:top="0dp" />
</shape>

2.在要设置边框的控件xml命令里加入:android:background=“@drawable/boder”

㈨ android 怎么设置item边框的颜色为灰色

首先重新定义一个style。在values文件夹下新建一个style.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="my_edittext_style" parent="@android:style/Widget.EditText">
<item name="android:background">@drawable/my_edittext</item>
</style>
</resources>
接下来在drawable里添加my_edittext.xml:内容如下
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/editbox_focus" /> <item android:drawable="@drawable/editbox_normal" />
</selector>
其中editbox_normal为正常情况下的编辑框图片,editbox_focus为选中下的编辑框图片

㈩ 怎么给android 设置边框

总结一下android ui界面里面如何设置边框,以及如何把边框设置成弧形的即圆角。
其实,android的ui里,界面一般都是比较简单的,不会像web页面那样,数据量比较大,关于给android界面(表格)设置边框,其思想很想我们用HTML设计表格然后给它设置边框,如果你懂html的话。即通过给不同的控件设置背景颜色来反衬出边框线
以一个登录界面为例,设置一个有边框线的android 登录界面:
注:本例要求的只是将该TableLayout中的行与行之间用边框线隔开
此例中,采用TableLayout布局,非常简单,里面有3个TableRow,分别放置 用户名、密码、登录按钮,根据上面说的设置边框线只需要设置控件的背景颜色即可。这个例子中要求行与行之间有边框线,那么,就这么想,
TableLayout:是该界面的布局管理器(当然也是一个控件),放在最外层,那么这时你可以给它选一个背景颜色参考注释 a)
TableRow:是表格中的一行,设置边框线重点就在此,它是紧跟着TableLayout的,可以给TableRow(行)设置背景色,参考b)
TableLayout与TableRow关系:可以看成父与子的关系,那么不管怎么样,TableLayout总是大于TableRow,那么通过给二者设置不同的颜色,设置颜色的时候可以让子组件(TableRow)周围稍微留出一点边界(就是它的背景色不会覆盖完整个行,如何让它显示成这样呢=====>android:layout_margin="0.5dip"[此属性即是设置该组件周围留出一点边界])
<?xml version="1.0" encoding="UTF-8"?>
<TableLayout
android:id="@+id/widget30"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
xmlns:android="
android:background="#ffcccccc" //a)给tablelayout设置背景色,改背景颜色将会是你要设置的边框线的背景色
android:layout_margin="1dip"
>
<!--android:background="@drawable/view_shape" -->
<TableRow
android:id="@+id/widget40"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99" //b)给tablerow设置背景色
android:layout_margin="0.5dip" //c)非常重要的一点
>
<TextView
android:id="@+id/widget41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login Name"
android:textStyle="bold"
android:layout_gravity="center_vertical" //如果想让表格里的列与列(column之间)也有边框线隔开,则同上面一样也要设置android:background="#ffffcc99"与android:layout_margin="0.5dip"
>
</TextView>
<EditText
android:id="@+id/widget42"
android:layout_width="141px"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<TableRow
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#ffffcc99"
android:layout_margin="0.5dip"
>
<TextView
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password"
android:textStyle="bold"
>
</TextView>
<EditText
android:id="@+id/widget45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:background="#ffffffff"
android:textColor="#ff000000"
>
</EditText>
</TableRow>
<Button
android:id="@+id/widget46"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textStyle="bold"
android:textColor="#ff000000"
android:layout_margin="2dip"
android:background="#ffffcc33"
>
<!--android:background="@drawable/view_shape" -->
</Button>
</TableLayout>

阅读全文

与android按钮设置边框颜色相关的资料

热点内容
排课走班源码 浏览:222
程序员刚毕业去了小公司有发展吗 浏览:90
速腾怎么安装安卓手机互联 浏览:143
linux设备驱动程序代码 浏览:301
服务器的功耗怎么看 浏览:651
app组件哪里找 浏览:87
androidqq红包 浏览:412
服务器如何传输 浏览:456
如何快速将多个文件夹快速解压缩 浏览:114
程序员睡前都在想什么 浏览:37
少儿编程技能培训心得 浏览:458
白命令 浏览:816
headfirstjavapdf 浏览:552
广数980t怎么编程 浏览:592
无邪app在哪里下载 浏览:462
mac自带php目录 浏览:632
海淘小程序源码 浏览:750
哪里下载苏宁秒达app 浏览:643
androidcmnet 浏览:31
易语言标题源码 浏览:948