RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
android设置样式,android怎么设置文本框样式

android设置控件样式(边框颜色,圆角)和图片样式(圆角)

本文链接:

为岭东等地区用户提供了全套网页设计制作服务,及岭东网站建设行业解决方案。主营业务为网站设计制作、成都网站设计、岭东网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

```

?xml version="1.0" encoding="utf-8"?

shape xmlns: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=""   

!-- 边框颜色值 --

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=""

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=""

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 App的样式风格

android中可以自定义主题和风格。风格,也就是style,我们可以将一些统一的属性拿出来,比方说,长,宽,字体大小,字体颜色等等。可以在res/values目录下新建一个styles.xml的文件,在这个文件里面有resource根节点,在根节点里面添加item项,item项的名字就是属性的名字,item项的值就是属性的值,如下所示:

复制代码 代码如下:

?xml version="1.0" encoding="utf-8"?

resources

style name="MyText" parent="@android:style/TextAppearance"

item name="android:textColor"#987456/item

item name="android:textSize"24sp/item

/style

/resources

style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:

复制代码 代码如下:

?xml version="1.0" encoding="utf-8"?

LinearLayout

xmlns:android="http://schemas。android。com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

EditText

android:id="@+id/myEditText"

android:layout_width="match_parent"

android:layout_height="match_parent"

style="@style/MyText"

android:text="测试一下下"/

/LinearLayout

说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:

复制代码 代码如下:

?xml version="1.0" encoding="utf-8"?

resources

style name="MyText" parent="@android:style/TextAppearance"

item name="android:textColor"#987456/item

item name="android:textSize"24sp/item

/style

style parent="@android:style/Theme" name="CustomTheme"

item name="android:windowNoTitle"true/item

item name="android:windowFrame"@drawable/icon/item

item name="android:windowBackground"?android:windowFrame/item

/style

/resources

style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:

复制代码 代码如下:

?xml version="1.0" encoding="utf-8"?

LinearLayout

xmlns:android="http://schemas。android。com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent"

EditText

android:id="@+id/myEditText"

android:layout_width="match_parent"

android:layout_height="match_parent"

style="@style/MyText"

android:text="测试一下下"/

/LinearLayout

说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:

复制代码 代码如下:

?xml version="1.0" encoding="utf-8"?

resources

style name="MyText" parent="@android:style/TextAppearance"

item name="android:textColor"#987456/item

item name="android:textSize"24sp/item

/style

style parent="@android:style/Theme" name="CustomTheme"

item name="android:windowNoTitle"true/item

item name="android:windowFrame"@drawable/icon/item

item name="android:windowBackground"?android:windowFrame/item

/style

/resources

可以看到这里写了一个继承自系统默认的Theme的主题,里面有3个属性,这里强调一下第三个属性的值的问题,这里打个问号,然后加前面的一个item的名字表示引用的是那个名字的值,也就是那个名字对应的图片。

然后我们在Manifest.xml里面的Application里面加一个Theme的属性,这个属性对应的就是我们上面写的Theme。

复制代码 代码如下:

application android:icon="@drawable/icon" android:label="@string/app_name"

android:theme="@style/CustomTheme"

activity android:name=".TestStyle"

android:label="@string/app_name"

intent-filter

action android:name="android.intent.action.MAIN" /

category android:name="android.intent.category.LAUNCHER" /

/intent-filter

/activity

上面的代码没有标题栏,背景和fram都是我们设置的图片。当然也可以在代码中设置主题:

复制代码 代码如下:

package com.test.shang;

import android.app.Activity;

import android.os.Bundle;

public class TestStyle extends Activity {

@Override

protected void onCreate (Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setTheme(R.style.CustomTheme);

setContentView(R.layout.test_style);

}

}

安卓手机怎么设置字体样式

手机字体怎么改?自去年华为荣耀3C刚出不久,就入手了。到现在也没有出什么问题,质量挺好的。因为华为的系统都是自己的,所以在这里跟大家分享一下华为手机改字体的诀窍。一起来看看吧!

华为手机改字体图文方法:

1、打开手机,找到设置图标。

2、点进去,找到显示这个选项。

3、就会看到“字体大小”跟“字体样式”两个选项。这也就是修改华为手机字体的地方了。

4、想要修改华为手机“字体大小”则比较简单,点击该选项即可。可以选择你想要的字体大小。

5、想要修改华为手机“字体样式”则点击该选项。进入页面之后,选择“在线”。

6、在“在线”的页面里选择“最新”,就看一看很多字体。

7、选择一个你喜欢的字体点击下载。

8、下载完毕之后,点击应用。而这时则需要重启手机。

9、重启完毕之后,该字体就已经应用在手机里了。

END

注意事项

该方法只适用于华为手机。

以上就是华为手机改字体图文方法,希望对大家有所帮助,谢谢大家阅读本篇文章!

怎样设置安卓系统手机上的字体啊?

1、首先我们进入设置,如图所示。

2、进入设置页面后,可以看见如图所示的搜索栏。

3、可以直接在设置页面的搜索栏中输入“字体样式”(如下图)

4、也可以下拉列表,点击“显示”选择“字体样式”(如下图)

5、再跳转到的页面,找到手机里面你喜欢的字体样式,如图所示。

6、然后点击“应用”,这时即可完成手机字体的修改,如图所示。


网页标题:android设置样式,android怎么设置文本框样式
URL地址:http://sczitong.cn/article/dsdgehp.html