導航:首頁 > 編程語言 > androidstyle代碼

androidstyle代碼

發布時間:2023-08-18 04:38:32

1. android 可以在程序代碼中設置style嗎

如果你是給textView的話,可以

textView.setTextAppearance(this, R.style.MyStyle);

其它的話就不行了。

2. android怎樣寫style

<style name="button_style">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginLeft">20dp</item>
<item name="android:layout_marginRight">20dp</item>
<item name="android:background">@drawable/button_click</item>
</style>

在res/values/styles 下邊 類似這樣寫 就可以 調用的話 style="@style/button_style"
記得 已經在 style中寫的東西 不要在button 下出現。不然會報錯誤


<Button
android:id="@+id/addLessonBtn"
style="@style/button_style"
android:text="@string/add_course_add" />

3. android中怎麼創建style

自定義樣式方法,可以直接通過定義xml文件來實現不同的樣式:
只需要修改button_style文件,同樣三種狀態分開定義:
Xml代碼
<?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值的相對位置

閱讀全文

與androidstyle代碼相關的資料

熱點內容
網站多少錢一單 瀏覽:382
系統鏡像恢復找不到文件 瀏覽:255
進什麼網站 瀏覽:588
修改了配置文件代碼沒有讀出來 瀏覽:749
vss資料庫是什麼 瀏覽:899
奇跡13單機系統找不到指定文件 瀏覽:719
flyme魅藍3以前的版本 瀏覽:318
安卓文件管理哪些文件夾可以刪除 瀏覽:290
安卓車載導航沒有聲音是怎麼回事 瀏覽:810
cjson數組格式 瀏覽:159
vb文件在哪裡 瀏覽:215
工廠里都招什麼編程人員 瀏覽:932
jspsql登錄 瀏覽:981
網路用語粉絲閱讀什麼意思 瀏覽:333
紅頭文件怎麼列印 瀏覽:94
熱血江湖130刺客升級 瀏覽:106
jsp頁面放大鏡技術介紹 瀏覽:101
網路編程udp 瀏覽:148
加密壓縮文件如何打開 瀏覽:56
微軟編程軟體有哪些 瀏覽:736

友情鏈接