當前位置:首頁 » 安卓系統 » android自定義樣式

android自定義樣式

發布時間: 2023-07-04 12:47:45

A. Android 中怎麼設置全局自定義字體樣式

  • 使用stackoverflow軟體進行修改。

  • 操作

  1. 首先下載自定義字體,拷貝到工程中的assets文件夾下,建個新文件夾也可以。

  2. 創建一個繼承自Application的類,放上TypeFace的變數。

  3. 將系統的serif的字體替換成微軟雅黑。

  4. 最後自定義的主題。

B. 如何修改安卓自定義水平progressdialog的樣式

android修改HOLO對話框風格

andriod中修改對話框的風格,可以通過設置theme來實現,部分元素需要通過Java代碼來修改,下面以修改對話框的標題為例說明各步驟。
1、編寫一個文本樣式。
DIALOG的標題是一個textview,在sytles.xml中,添加如下代碼來設置你自己的文本樣式:
<style name="DialogWindowTitle">
<item name="android:textSize">22sp</item>
<item name="android:textColor">@color/font_dark_grey</item>
</style>
2、設置對話框的標題主題。

上面的標題文本並不能直接設置為對話框的標題樣式。 我們還需要編寫一個表示標題的主題的style,在這里指定標題的文本樣式。代碼如下:

<style name="DialogWindowTitle.DeviceDefault">
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:textAppearance">@style/DialogWindowTitle</item>
</style>

3、設置對話框主題。

接下來,我們編寫我們的對話框主題,在這里指定標題的主題。由於一些屬性並不是public的,所以我們需要繼承自原來的某個style,代碼如下:

<!--Dialog主題-->
<style name="Theme.DeviceDefault.Dialog" parent="@android:style/Theme.DeviceDefault.Light.Dialog" >
<item name="android:windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>
</style>

4、自定義App的主題。

接下來,我們需要在我們的App theme中指定我們的對話框使用這種主題,所以需要定義一個App theme。同樣由於App theme的許多屬性並不是public的(比如下面要提到的標題下面的那條藍線),所以我們要繼承自一個原生的style。這里我根據程序需要選擇了Theme.Holo.Light.NoActionBar,代碼如下:

<style name="ParkingTheme" parent="@android:style/Theme.Holo.Light.NoActionBar">
<item name="android:dialogTheme">@style/Theme.DeviceDefault.Dialog</item>
</style>
5、指定App主題。

最後一步,我們需要在AndroidManifest.xml文件中,指定我們的app主題。這步很簡單,只需要在application標簽中指定android:theme的值即可,如下:

android:theme="@style/ParkingTheme"

C. 如何為Android studio設置自定義的主題樣式

Android Studio默認主題IntelliJ,我們可以修改成黑色的Dracula的主題或者是Windows主題。 1、首先雙擊桌面AndroidStudio圖標,打開Android Studio。 2、選擇Android Studio菜單欄File——Settings選項 3、或者在工具欄中直接點擊Settings設置圖。詳細的可以看看安卓巴士教程:http://www.apkbus.com/thread-463460-1-1.html

D. 如何自定義android Button樣式

1)自定義button樣式
一、採用圖片方式
首先新建Android XML文件,類型選Drawable,根結點選selector,自定義一個文件名。
隨後,開發環境自動在新建的文件里加了selector結點,我們只需要在selector結點里寫上三種狀態時顯示的背景圖片(按下、獲取焦點,正常)即可。具體如下:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/play_press" ;/>
<item android:state_focused="true" android:drawable="@drawable/play_press" ;/>
<item android:drawable="@drawable/play" ;/>
</selector>

註:這里獲取焦點跟點擊時顯示的是同一張圖片,必須嚴格照上面的順序寫,不可倒。
最後,只要在布局時寫Button控制項時應用到Button的Background屬性即可,如:
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/button_style">
</Button>
二、採用自定義方式
在源代碼中,只需要修改button_style文件,同樣三種狀態分開定義:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<gradient android:startColor="#0d76e1"
android:endColor="#0d76e1"
android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>

<item android:state_focused="true">
<shape>
<gradient android:startColor="#ffc2b7" android:endColor="#ffc2b7" android:angle="270" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="2dp" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>

<item>
<shape>
<gradient android:startColor="#000000" android:endColor="#ffffff"
android:angle="180" />
<stroke android:width="1dip" android:color="#f403c9" />
<corners android:radius="5dip" />
<padding android:left="10dp" android:top="10dp"
android:right="10dp" android:bottom="10dp" />
</shape>
</item>
</selector>

註:代碼中的各屬性含義為:
gradient 主體漸變
startColor開始顏色,endColor結束顏色 ,
angle開始漸變的角度(值只能為90的倍數,0時為左到右漸變,90時為下到上漸變,依次逆時針類推)
stroke 邊框 width 邊框寬度,color 邊框顏色
corners 圓角 radius 半徑,0為直角
padding text值的相對位置
2)自定義style樣式
一、在style.xml中自定義樣式
以自定義text文本大小和顏色為例,自定義一個名稱為"testStyle"的style代碼如下:

<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
</style>

<style name="testStyle">
<item name="android:textSize">30px</item>
<item name="android:textColor">#1110CC</item>
<item name="android:width">150dip</item>
<item name="android:height">150dip</item>
</style>
</resources>

二、在layout文件中引用自定義的"testStyle"的style樣式

<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"
tools:context=".MainActivity" >

<TextView
style="@style/testStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />

</RelativeLayout>

E. 如何自定義android Button樣式

在windows7操作系統Android studio中按照如下方法定義button的樣式。

1、首先使用Android studio創建一個項目,項目結構如下:

F. android 自定義view 怎麼規定view的樣式

android 自定義view的樣式的實現:

1.在values文件夾下,打開attrs.xml,其實這個文件名稱可以是任意的,寫在這里更規范一點,表示裡面放的全是view的屬性。

2.因為我們下面的實例會用到2個長度,一個顏色值的屬性,所以我們這里先創建3個屬性。

<declare-styleable name="rainbowbar">
<attr name="rainbowbar_hspace" format="dimension"></attr>
<attr name="rainbowbar_vspace" format="dimension"></attr>
<attr name="rainbowbar_color" format="color"></attr>
</declare-styleable>

舉例說明:

藍色的進度條

public class RainbowBar extends View {

//progress bar color
int barColor = Color.parseColor("#1E88E5");
//every bar segment width
int hSpace = Utils.dpToPx(80, getResources());
//every bar segment height
int vSpace = Utils.dpToPx(4, getResources());
//space among bars
int space = Utils.dpToPx(10, getResources());
float startX = 0;
float delta = 10f;
Paint mPaint;

public RainbowBar(Context context) {
super(context);
}

public RainbowBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public RainbowBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
//read custom attrs
TypedArray t = context.obtainStyledAttributes(attrs,
R.styleable.rainbowbar, 0, 0);
hSpace = t.getDimensionPixelSize(R.styleable.rainbowbar_rainbowbar_hspace, hSpace);
vSpace = t.getDimensionPixelOffset(R.styleable.rainbowbar_rainbowbar_vspace, vSpace);
barColor = t.getColor(R.styleable.rainbowbar_rainbowbar_color, barColor);
t.recycle(); // we should always recycle after used
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setColor(barColor);
mPaint.setStrokeWidth(vSpace);
}

.......
}

View有了三個構造方法需要我們重寫,這里介紹下三個方法會被調用的場景,

第一個方法,一般我們這樣使用時會被調用,View view = new View(context);

第二個方法,當我們在xml布局文件中使用View時,會在inflate布局時被調用,
<View layout_width="match_parent" layout_height="match_parent"/>。

第三個方法,跟第二種類似,但是增加style屬性設置,這時inflater布局時會調用第三個構造方法。
<View style="@styles/MyCustomStyle" layout_width="match_parent" layout_height="match_parent"/>。

G. Android自定義Switch樣式

如圖自定義的Switch樣式:

需要注意的是:switch的大小是跟thumb的大小有關
下面以樣式二為例:

switch_track_bg_selected.xml

switch_track_bg_normal.xml

switch_thumb_bg_selected.xml

switch_thumb_bg_normal.xml

詳細參考: Android Switch自定義樣式

熱點內容
python處理excel文件 發布:2025-02-06 16:36:09 瀏覽:439
演算法相對定位 發布:2025-02-06 16:32:42 瀏覽:725
java程序的編譯和執行 發布:2025-02-06 16:21:45 瀏覽:416
什麼是淘寶帳號和密碼 發布:2025-02-06 16:21:36 瀏覽:495
解壓前面簽 發布:2025-02-06 16:02:00 瀏覽:324
華碩訪問點 發布:2025-02-06 15:56:57 瀏覽:331
excel拼接sql 發布:2025-02-06 15:50:10 瀏覽:501
加密手機直播 發布:2025-02-06 15:49:31 瀏覽:535
自帶ftp伺服器好用嗎 發布:2025-02-06 15:26:11 瀏覽:110
win7訪問xp區域網 發布:2025-02-06 15:17:07 瀏覽:525