導航:首頁 > 操作系統 > 安卓怎麼寫樣式

安卓怎麼寫樣式

發布時間:2022-07-11 13:44:07

① 安卓開發中怎麼在布局中添加顯得樣式

使用TableLayout表格布局

表格布局模型以行列的形式管理子控制項,每一行為一個TableRow的對象,當然也可以是一個View的對象。TableRow可以添加子控制項,每添加一個為一列。
TableLayout屬性:
android:collapseColumns:將TableLayout裡面指定的列隱藏,若有多列需要隱藏,請用逗號將需要隱藏的列序號隔開。
android:stretchColumns:設置指定的列為可伸展的列,以填滿剩下的多餘空白空間,若有多列需要設置為可伸展,請用逗號將需要伸展的列序號隔開。
android:shrinkColumns:設置指定的列為可收縮的列。當可收縮的列太寬(內容過多)不會被擠出屏幕。當需要設置多列為可收縮時,將列序號用逗號隔開。
列元素(Button)屬性:(奇怪的是button 裡面沒有android:layout_column 和android:layout_span兩個屬性,寫進去無反應,還不知道為什麼)
android:layout_colum:設置該控制項在TableRow中指定的列。
android:layout_span:設置該控制項所跨越的列數。

② 安卓手機上怎麼打出好看的字體

1、點擊手機設置


(2)安卓怎麼寫樣式擴展閱讀:

花樣字體設置之後,還可以通過設置字體的大小來設置自己最喜歡的狀態:

不同的字體選擇好以後,也能在系統中設置字體大小,就可以對手機的字體進行調整了,手機提供的調整方式有4種,分別是「小號~默認~中號~大號~超大」,只需根據需要選擇就好了。

這樣就會手機使用起來有不同的感覺,也能更好的匹配不同的人群, 相信這樣使用會更喜歡的。

另外,有一點要注意的是:這里調整的字體大小隻適用於系統本身(設置、桌面字體)的字體大小,不能改變第三方APP內字體的大小,第三方APP的字體大小需要第三方軟體提供調整入口才行。不同手機的調整方法不太一樣但是基本都是一樣的。

③ Android開發之:如何使用樣式和主題

�塵把丈�仁糶浴Q�絞譴硬季治募�蟹擲氤隼吹囊桓鯴ML資源文件。Android中的樣式就像Web開發中的css樣式表,它使用我們的樣式獨立於內容進行設計開發。 例如,通過使用一個樣式可以讓如下的布局文件簡化為:所有和樣式有關的屬性都被從布局XML文件中移動到一個叫「CodeFont」的樣式定義中,然後使用一個style屬性指定樣式名稱。你將會在以下的內容中看到如何定義一個樣式。應用於一個Activity或應用程序的樣式稱為主題(theme),而不是剛才說的一個View。所有在當前Activity或應用下的視圖(VIEW)都會應用相同的主題樣式。例如,您可以讓一個Activity使用」CodeFont」主題,那麼這個Activity下的所有視圖的的文本都將是綠色等寬字體。定義樣式定義樣式我們需要在 res/values/目錄下新建一個XML文件,文件名自已隨便命名,但必須以.xml為文件後綴。Xml的根節點必須為。 我們用style標簽來定義一個樣式,用標簽來定義樣式屬性。如下所示:fill_parentwrap_content#00FF00monospaceStyle標簽的name屬性是必須有的,節點可以定義顏色、高度或者是另一個資源的引用。所有節點的子節點在編譯時都會做為應用程序的一個資源。所以我們可以通過style節點的name屬性值來引用這個資源。比如在布局文件中使用@style/CodeFont來引用這個樣式。parent 屬性是可選的,用它來標識本樣式是繼承哪個樣式,在父樣式中的所有屬性都將被應用於本樣式中,同時可以覆蓋父樣式中的樣式(和java的繼承相似)。樣式的繼承這里有兩種方式可以實現樣式繼承,如上例中所示的,我們可以在定義樣式時使用parent屬性來繼承樣式,使用這種方式,我們可以繼承一個我們自己定義好的樣式,也可以繼承一個android平台自帶的樣式(後文中會介紹android平台自帶的所有樣式)。如下所示,我們繼承一個android平台默認的文本樣式,並把它的字體顏色改為我們需要的顏色。#00FF00另一種繼承的方式是使用用戶自定義的樣式作為前綴即可。這種方式只適用於繼承用戶自定義樣式。如下所示:#FF0000這樣,新定義的樣式就會繼承CodeFont樣式的所有屬性,然後把字體顏色變為#FF0000。我們可以這樣引用新的樣式: @style/CodeFont.Red 相同的方法,我們可以再繼承下去,如下所示:30sp這樣新的樣式文子的大小就和CodeFont.Red樣式不同了。樣式屬性到這里為止,你已經知道了如何定義一個樣式,你還需要知道有多少種樣式屬性可以通過節點來定義。你可能已經對其中的一些比較熟悉了,如layout_width 、textColor等。當然,還有很多的樣式屬性是你可以使用的。

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

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

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

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

  4. 最後自定義的主題。

⑤ Android 怎樣在styles.xml中定義自己的樣式並引用樣式

下面是styles.xml文件中相關的部分:

[html] view plain print?

<stylename="text_font">

<itemname="android:textColor">#05b</item>

<itemname="android:textSize">18sp</item>

<itemname="android:textStyle">bold</item>

</style>

<stylename="content_font">

<itemname="android:textColor">#0f5</item>

<itemname="android:textSize">18sp</item>

<itemname="android:textStyle">normal</item>

</style>

<stylename="hint_text_font"parent="text_font">

<itemname="android:textColor">#f00</item>

</style>

<style name="text_font">
<item name="android:textColor">#05b</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="content_font">
<item name="android:textColor">#0f5</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">normal</item>
</style>

<style name="hint_text_font" parent="text_font">
<item name="android:textColor">#f00</item>
</style>


我們在界面元素中這樣引用:

[html] view plain print?

<TextViewstyle="@style/content_font"

android:id="@+id/textView1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello_world"/>

<Buttonstyle="@style/text_font"

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/test_IntentService"/>

<TextViewstyle="@style/hint_text_font"

android:id="@+id/hint"

android:text="@string/hint_text"

android:layout_height="wrap_content"

android:layout_width="fill_parent"/>

上面截圖就是通過自定義樣式實現的,例子來自android學習手冊,裡面有源碼。android學習手冊包含9個章節,108個例子,源碼文檔隨便看,例子都是可交互,可運行,源碼採用android studio目錄結構,高亮顯示代碼,文檔都採用文檔結構圖顯示,可以快速定位。360手機助手中下載,圖標上有貝殼:

⑥ 如何自定義android Button樣式

親,可以用到Drawable中的shape哦,給你一個demo

<?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="

<itemandroid:state_focused="false">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="#C8C8C8"/>
</shape>
</item>

<itemandroid:state_focused="true">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="@color/main_color"/>
</shape>
</item>

</selector>

各個屬性的介紹

solid:實心,就是填充的意思
android:color指定填充的顏色

gradient:漸變
android:startColor和android:endColor分別為起始和結束顏色,ndroid:angle是漸變角度,必須為45的整數倍。
另外漸變默認的模式為android:type="linear",即線性漸變,可以指定漸變為徑向漸變,android:type="radial",徑向漸變需要指定半徑android:gradientRadius="50"。

stroke:描邊
android:width="2dp"描邊的寬度,android:color描邊的顏色。
我們還可以把描邊弄成虛線的形式,設置方式為:
android:dashWidth="5dp"
android:dashGap="3dp"
其中android:dashWidth表示'-'這樣一個橫線的寬度,android:dashGap表示之間隔開的距離。

corners:圓角
android:radius為角的弧度,值越大角越圓。
我們還可以把四個角設定成不同的角度,方法為:
<corners
android:topRightRadius="20dp"右上角
android:bottomLeftRadius="20dp"右下角
android:topLeftRadius="1dp"左上角
android:bottomRightRadius="0dp"左下角
/>

我自己寫的一個按鈕,效果就像圖中所示,用的Shape



新建後存放位置在res/drawable下


希望能幫到你,還望採納

⑦ 簡述Android 中樣式文件使用步驟

在Eclipse中android程序項目目錄結構下的res文件夾新建drawable文件夾,並在drawable文件夾下新建各類的xml樣式文件,供layout文件夾下的xml布局文件引用,以滿足對程序界面的需求開發。如圖1和圖2是drawable下xml樣式文件的樣式類型。

圖3、iv1到iv4
其次是信號增強即圖片順序播放的效果,在drawable下新建animation_list_sequence.xml樣式文件。

<?xml version="1.0" encoding="utf-8"?><!--
根標簽為animation-list;
其中oneshot代表著是否只展示一遍,設置為false會不停的循環播放動畫;
其中visible規定drawable的初始可見性,默認為flase;
其中variablePadding若為true則允許drawable的距離在當前選擇狀態下有所改變(If true, allows the drawable』s padding to change based on the current state that is selected.),默認為false;
根標簽下,通過item標簽對動畫中的每一個圖片進行聲明;
android:ration 表示展示所用的該圖片的時間長度,單位為毫秒;
--><animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
android:visible="false"
android:variablePadding="false"
>
<item android:drawable="@drawable/iv1" android:ration="200"></item>
<item android:drawable="@drawable/iv2" android:ration="200"></item>
<item android:drawable="@drawable/iv3" android:ration="200"></item>
<item android:drawable="@drawable/iv4" android:ration="200"></item></animation-list>

再者是信號增強即圖片順序播放的效果,在drawable下新建animation_list_reverse.xml樣式文件。

<?xml version="1.0" encoding="utf-8"?><!--
根標簽為animation-list;
其中oneshot代表著是否只展示一遍,設置為false會不停的循環播放動畫;
其中visible規定drawable的初始可見性,默認為flase;
其中variablePadding若為true則允許drawable的距離在當前選擇狀態下有所改變(If true, allows the drawable』s padding to change based on the current state that is selected.),默認為false;
根標簽下,通過item標簽對動畫中的每一個圖片進行聲明;
android:ration 表示展示所用的該圖片的時間長度,單位為毫秒;
--><animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
android:visible="false"
android:variablePadding="false"
>
<item android:drawable="@drawable/iv4" android:ration="200"></item>
<item android:drawable="@drawable/iv3" android:ration="200"></item>
<item android:drawable="@drawable/iv2" android:ration="200"></item>
<item android:drawable="@drawable/iv1" android:ration="200"></item></animation-list>

然後在layout文件夾下新建xml布局文件activity_animation_list.xml,引用上面寫好的drawable文件夾下的xml樣式文件。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView android:id="@+id/iv_animation_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/animation_list_sequence" />

<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="sequence"
android:text="順序顯示" />

<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="stop"
android:text="停止動畫" />

<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="reverse"
android:text="倒序顯示" /></LinearLayout>2122232425262728293031

然後在src包下新建Activity的Java文件AnimationListActivity.java,用於演示操作。

package com.zcz.drawablexmltest;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.view.View;import android.view.Window;import android.widget.ImageView;public class AnimationListActivity extends Activity{
private ImageView mIv;
private AnimationDrawable mAd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_animation_list);
mIv = (ImageView) findViewById(R.id.iv_animation_list);
}

public void sequence(View view){
mIv.setImageResource(R.drawable.animation_list_sequence);
mAd = (AnimationDrawable) mIv.getDrawable();
mAd.start();
} public void stop(View view){
mAd = (AnimationDrawable) mIv.getDrawable();
mAd.stop();
} public void reverse(View view){
mIv.setImageResource(R.drawable.animation_list_reverse);
mAd = (AnimationDrawable) mIv.getDrawable();
mAd.start();
}
}

⑧ 如何修改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);
}
}

閱讀全文

與安卓怎麼寫樣式相關的資料

熱點內容
真實的幸福pdf 瀏覽:342
d盤php調用c盤的mysql 瀏覽:264
怎麼樣搭建源碼網站 瀏覽:427
新概念四冊pdf 瀏覽:361
怎麼下載悅虎檢測app 瀏覽:528
cad表達式命令 瀏覽:198
程序員去一個小公司值不值得 瀏覽:846
程序員做個程序多少錢 瀏覽:495
win10原始解壓軟體 瀏覽:319
阿里程序員的老家 瀏覽:258
量子加密銀行 瀏覽:193
命令方塊獲得指令手機 瀏覽:499
學習結束感言簡短程序員 瀏覽:398
android關機鬧鍾實現 瀏覽:968
滑鼠一鍵打開文件夾設置 瀏覽:161
程序員看過來我想靜靜搞笑視頻 瀏覽:370
curlphp爬蟲 瀏覽:874
python按日期循環 瀏覽:110
php三個等號 瀏覽:760
培訓班出來的程序員解決問題很差 瀏覽:963