導航:首頁 > 編程語言 > 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代碼相關的資料

熱點內容
哪些統計量可以反映數據波動 瀏覽:946
js地圖標記怎麼清空 瀏覽:479
googlenow教程 瀏覽:508
安全四個責任體系內容文件 瀏覽:965
南陽政務app怎麼注冊 瀏覽:343
照片壓縮包同一路徑的文件能刪嗎 瀏覽:590
路由沒網路怎麼辦 瀏覽:745
南京網站推廣大概多少錢 瀏覽:983
js隱藏列印出來 瀏覽:135
手工之家app哪裡下載 瀏覽:328
網路教育聯盟英語考試是什麼 瀏覽:69
macairwin10忘記密碼 瀏覽:716
java上傳方法 瀏覽:970
csc文件夾可以刪除嗎 瀏覽:130
打線工具怎麼用 瀏覽:376
mat文件如何轉換為cad 瀏覽:761
qq瀏覽器舊版本614 瀏覽:713
將資料庫文件批量導出excel 瀏覽:262
招投標文件在招標公司存多少年 瀏覽:551
u盤空間不足不能復制系統鏡像文件 瀏覽:212

友情鏈接