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

熱點內容
計算機網路的概念是什麼 瀏覽:625
網路硬碟存儲製作 瀏覽:4
iphone怎麼備份數據到電腦 瀏覽:41
微信小程序報表控制項 瀏覽:722
ipad添加不了qq郵箱賬號和密碼 瀏覽:503
matlab中文文件名 瀏覽:236
excel是啥類型文件 瀏覽:471
安慶培訓編程怎麼選 瀏覽:817
vs2010mfc工具箱 瀏覽:402
刪除文件重置win10怎麼恢復 瀏覽:180
新裝win10有線連不上 瀏覽:785
資料庫商品名唯一怎麼標注 瀏覽:214
電信5g網路什麼時候出 瀏覽:626
手機如何把視頻打包到文件夾裡面 瀏覽:248
excel數據轉vcf文件 瀏覽:585
編程題如何左右翻轉 瀏覽:920
wp10微信安裝不了 瀏覽:793
微軟資料庫密碼怎麼改 瀏覽:627
我們是貴族什麼app可以看 瀏覽:65
哪個app認字免費 瀏覽:964

友情鏈接