當前位置:首頁 » 安卓系統 » 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都沒有改變下拉樣式的功能。改變主題可以換個皮膚

熱點內容
我的世界怎樣刷出32k伺服器 發布:2024-05-18 14:32:32 瀏覽:565
c語言程序設計江寶釧 發布:2024-05-18 14:32:22 瀏覽:780
右擊文件夾總是轉圈圈 發布:2024-05-18 14:31:10 瀏覽:695
新建資料庫phpmyadmin 發布:2024-05-18 14:22:38 瀏覽:735
安卓手機設備連接在哪裡 發布:2024-05-18 14:08:28 瀏覽:819
路由器的密碼最多是多少位 發布:2024-05-18 13:58:18 瀏覽:419
掃描伺服器名稱如何填 發布:2024-05-18 13:36:29 瀏覽:115
芒果緩存的視頻看不了視頻怎麼下載不了 發布:2024-05-18 13:35:14 瀏覽:519
c語言發簡訊 發布:2024-05-18 13:23:08 瀏覽:834
vb資料庫程序 發布:2024-05-18 13:01:57 瀏覽:113