当前位置:首页 » 安卓系统 » android设置样式

android设置样式

发布时间: 2022-11-20 02:17:09

㈠ 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 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刚出不久,就入手了。到现在也没有出什么问题,质量挺好的。因为华为的系统都是自己的,所以在这里跟大家分享一下华为手机改字体的诀窍。一起来看看吧!

注意事项

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

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

㈣ Android Studio控件设置样式怎么设置


1、样式定义
android的样式定义在res/values/style.xml文件中,类似web前端中将样式定义在某个css文件中,但android的style.xml是自动加载的,不需要手动import或link。目前还不了解android是否可以或怎么定义多个style文件。

如下是一组样式的定义

[xml]
<span style="background-color: rgb(255, 255, 255);"> <!-- 全局字体样式-->
<style name="DefaultFontStyle">
<item name="android:textSize">18px</item>
<item name="android:textColor">#0000CC</item>
</style>

<!-- 全局背景色-->
<style name="DefaultBgColor" parent="@style/DefaultFontStyle">
<item name="android:background">#F2F2F2</item>
</style>

<!-- 全局样式-->
<style name="DefaultStyle" parent="@style/DefaultBgColor">
</style></span>

a. android的样式定义是通过style标签完成的,通过添加item元素设置不同的属性值
b. 样式可以通过设置parent进行继承。上面的DefaultBgColor继承自DefaultFontStyle,而DefaultStyle又继承自DefaultBgColor,这样DefaultStyle就有了字体大小颜色、背景色的属性了。
c. android的主题样式和一般样式的定义是一样的,只是引用时不同2、单个view如何设置样式

比如TextView,设置样式如下
[xml]
<span style="background-color: rgb(255, 255, 255);"><TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我在做什么:"
android:textSize="18px"
android:textColor="#0000CC"
/></span>

也可以引用第一部分定义的样式,如下

[xml]
<span style="background-color: rgb(255, 255, 255);"><TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="我在做什么:"
style="@style/DefaultStyle"
/></span>
设置view的style属性进行样式调用,推荐使用此种方式将样式和布局分离。其他view及viewGroup设置相同。3、全局样式设置

在web前端编程中,可以使用
[html]
<span style="background-color: rgb(255, 255, 255);">body {
background: #cce8cf;
color: #000;
font-family: 宋体 verdana, tahoma;
font-size: 18px;
padding: 1px 2px 0 2px;
counter-reset: section;
}</span>
设置全局的样式

[html]
<span style="background-color: rgb(255, 255, 255);">div {
margin-top: 10px;
margin-bottom: 10px;
}</span>
设置单个标签的样式

㈤ Android Studio控件设置样式怎么设置

在windows7操作系统,Android studio中使用按照如下步骤设置Android Studio编辑中的代码字体的样式。
1、打开Android studio的设置界面,点击工具的扳手图标,

2、在设置搜索栏输入"Font",

3、更改一下设置,“Primary font”是更改字体样式,比如“楷体”,“Size”我们可以更改字体的大小,“Line spacing”可以更改行间距,如下图:

4、更改之后单击“Apply”应用更改,然后单击“OK”,

㈥ Android Studio控件设置样式怎么设置

Android Studio控件设置样式设置:
在windows7操作系统,Android studio中使用按照如下步骤设置Android Studio编辑中的代码字体的样式。
1、打开Android studio的设置界面,点击工具的扳手图标
2、在设置搜索栏输入"Font"
3、更改一下设置,“Primary font”是更改字体样式,比如“楷体”,“Size”我们可以更改字体的大小,“Line spacing”可以更改行间距
4、更改之后单击“Apply”应用更改,然后单击“OK”

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

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

㈧ Android Studio控件设置样式怎么设置

1、在安卓项目的layout文件夹中添加一个布局文件:activity_main.xml,在该布局文件中添加一个Button控件。

2、在安卓项目的values文件夹中有一个colors.xml文件,里面用来存放一些颜色值,有一个dimens.xml文件,里面用来存放一些尺寸值,可以用来设置控件字体的大小。

3、在colors.xml文件中设置好颜色值、在dimens.xml文件中设置好尺寸值之后就可以在layout文件中为控件设置颜色和字体大小了。在activity_main.xml文件中,从colors.xml文件中选择一个颜色值赋值给Button控件的android:background属性,可以设置控件的背景颜色;从dimens.xml文件中选择一个尺寸值赋值给Button控件的android:textSize属性,可以设置控件的字体大小。

㈨ android studio怎么设置代码字体样式

我们在刚开始使用Android Studio开发Android项目的时候,会发现Android Studio初始化的字体大小和字体样式以及段落并不让我们感到很舒服,总觉得不满意,那么我们就可以自己来定义属于自己的代码字体风格,记下来小编就教大家怎样更改Android Studio代码字体的样式

工具/原料
Android Studio 1.2.2
电脑
方法/步骤
首先找到菜单栏,单击菜单栏的“File”菜单

在弹出的二级菜单中选中“Settings”选项,单击它,打开设置窗口

在设置窗口中的左边部分单击“Editor”选项,展开

在展开的下一级菜单中,找到“Colors & Fonts”选项,展开它

然后在展开的,菜单中选择“Font”选项,打开Font字体设置窗口

在打开的“Font”窗口中,找到“Save As...”按钮,单击它,在弹出的对话框中为自己的设置起一个名字,如果不单击“Save As...”新建一个样式的话,Android Studio默认是不给我们更改的

在弹出的对话框中,输入我们更改后需要保存的样式的名称,然后单击“OK”

接下来我们就可以进行更改设置了,“Primary font”是更改字体样式,比如“楷体”,“Size”我们可以更改字体的大小,“Line spacing”可以更改行间距

更改完成之后我们单击“Apply”应用更改,然后单击“OK”

㈩ android怎样自定义设置下拉列表样式

除了个别内容能自己改变,绝大多数的ROM都没有改变下拉样式的功能。改变主题可以换个皮肤

热点内容
气瓶如何存储 发布:2025-03-06 11:51:28 浏览:553
爱奇艺会员怎么改密码 发布:2025-03-06 11:33:44 浏览:61
firefox不缓存 发布:2025-03-06 11:33:43 浏览:467
淘宝密码如何破解 发布:2025-03-06 11:32:56 浏览:593
sqlservereclipse 发布:2025-03-06 11:25:29 浏览:705
linux存放文件 发布:2025-03-06 11:24:47 浏览:447
nfslinux挂载 发布:2025-03-06 11:19:42 浏览:234
安卓动态壁纸怎么提取 发布:2025-03-06 11:07:26 浏览:112
有锁安卓手机有什么坏处 发布:2025-03-06 11:00:20 浏览:576
dvwa上传 发布:2025-03-06 10:46:58 浏览:700