如何在一個xml中設置文本大小,文本顏色和其他參數,並將它們分配給android中的imagebutton? 我可以爲每個按鈕手動設置參數,但是如果有超過3個按鈕,它將變成一場噩夢。這樣做的最佳做法是什麼?如何在android中爲imagebutton設置textsize,textcolor和其他參數?
0
A
回答
1
1
創建style
根據您的要求的是添加到您的按鈕,這樣style="@style/your_style"
。看看這個教程Styles and Themes
0
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomText" parent="@style/Text">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#008</item>
</style>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<EditText
style="@style/CustomText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#00FF00"
android:typeface="monospace"
android:text="@string/hello" />
+0
警告:在佈局文件中發現意外的文本:「20sp」。我不知道它是否重要,但我把樣式XML放在可繪製的文件夾中 – Alex 2012-08-08 10:21:49
相關問題
- 1. 如何從代碼中設置TextColor,PagerTitleStrip的TextSize?
- 2. 如何設置SearchView TextSize?
- 3. 如何設置EditText TextSize?
- 4. 其他設置ImageButton維度的方法
- 5. Android設置ImageButton爲切換
- 6. Android的addView設置TextView textColor爲白色?
- 7. 如何設置TextColor Xamarin.Forms TableSection?
- 8. MySQL:如何設置Linesize和其他環境參數
- 9. 如何在android 2.1中設置按鈕的「textColor」屬性?
- 10. 如何在JupyterHub中設置NotebookApp.iopub_data_rate_limit和其他NotebookApp設置?
- 11. Android ContextMenu如何設置TextColor和bg顏色?
- 12. 設置可選參數將其他參數的默認值設置爲零
- 13. Xamarin Android - 從Dimension文件設置TextSize
- 14. 如何在onCreateView中設置imagebutton src?
- 15. 設置背景顏色和設置圖像在ImageButton背景 - Android
- 16. 如何在android中自動調整textSize?
- 17. 將JavaScript函數設置爲用於其他函數的參數?
- 18. 如何隨機設置ImageButton?
- 19. 如何在Android中單擊ImageButton時設置文本?
- 20. 如何在xCode中爲其他目標設置其他C標誌?
- 21. 如何爲Android Imagebutton設置20%的alpha值?
- 22. 在ImageButton中設置文本
- 23. Android ViewModel其他參數
- 24. 在C++的其他類中設置模板參數
- 25. Android在Imagebutton上設置動態圖像
- 26. 如何在其他wordpress設置中添加wordpress設置?
- 27. ImageButton將src設置爲StateListDrawable
- 28. 如何設置菜單項不可cliquable Android與textcolor白色?
- 29. 在Android中增加textSize
- 30. 如何在Java中爲不同狀態設置Android ImageButton backgroundimage代碼
學習Android開發可重複使用的資源的一些基本的,你可以創建/ RES /值的樣式/和外觀類似的部件使用這些風格,深受風格=「@風格/ your_style」 – 2012-08-08 10:04:44