<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>

新聞中心

EEPW首頁(yè) > 嵌入式系統 > 設計應用 > Android――設置字體的大小與樣式

Android――設置字體的大小與樣式

作者: 時(shí)間:2016-09-12 來(lái)源:網(wǎng)絡(luò ) 收藏

一個(gè)按鈕改變字體的大小,一個(gè)按鈕改變字體的樣式

本文引用地址:http://dyxdggzs.com/article/201609/305028.htm

Activity核心代碼:

public class Ex03_14 extends Activity

{

private TextView mText;

private Button sizeButton;

private Button fontButton;

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

mText=(TextView)findViewById(R.id.mytextview);

sizeButton=(Button) findViewById(R.id.sizebutton);

fontButton=(Button) findViewById(R.id.fontbutton);

sizeButton.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v)

{

mText.setTextSize(20); //設置字體大小為20

}

}

);

fontButton.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v)

{

mText.setTypeface(Typeface.DEFAULT_BOLD,Typeface.ITALIC); //設置系統默認的字體樣式

// mText.setTypeface

// (Typeface.createFromAsset(getAssets(),fonts/HandmadeTypewriter.ttf)); //設置自己的字體樣式

}

}

);

}

}

說(shuō)明:必須事先在assets底下創(chuàng )建一個(gè)fonnts文件夾,并放入要使用的字體文件(.ttf),并提供相對路徑給createFronAsset()來(lái)創(chuàng )建Typeface對象。但是Android對字體支持不太好,可能有些字體文件不支持,但也不會(huì )報錯,只是在運行過(guò)程中使用默認的字體樣式。另外不僅可通過(guò)外部資源來(lái)構造Typeface,也可以通過(guò)defaultFromStyle使用Android內置的幾款Typeface.

int BOLD (Typeface.BOLD)

int BLOD_ITALIC

int ITALIC

int NORMAL

Typeface DEFAULT_BOLD (Typeface.DEFAULT_BOLD)

Typeface DEFAULT

Typeface MONSPACE

Typeface SANS_SERIF

Typeface SERIF

另外說(shuō)明一點(diǎn):

Button.OnClickListener相當于一個(gè)接口,但看起來(lái),Button本身沒(méi)有OnClickListener這個(gè)接口。

android.view.View.OnClickListener說(shuō)明OnClickListener這個(gè)接口是屬于View的。

Button更改成EditText,View也是運行正確的!



關(guān)鍵詞:

評論


相關(guān)推薦

技術(shù)專(zhuān)區

關(guān)閉
国产精品自在自线亚洲|国产精品无圣光一区二区|国产日产欧洲无码视频|久久久一本精品99久久K精品66|欧美人与动牲交片免费播放
<dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><small id="yhprb"></small><dfn id="yhprb"></dfn><small id="yhprb"><delect id="yhprb"></delect></small><small id="yhprb"></small><small id="yhprb"></small> <delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"></dfn><dfn id="yhprb"></dfn><s id="yhprb"><noframes id="yhprb"><small id="yhprb"><dfn id="yhprb"></dfn></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><small id="yhprb"></small><dfn id="yhprb"><delect id="yhprb"></delect></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn> <small id="yhprb"></small><delect id="yhprb"><strike id="yhprb"></strike></delect><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn><dfn id="yhprb"><s id="yhprb"><strike id="yhprb"></strike></s></dfn><dfn id="yhprb"><s id="yhprb"></s></dfn>