How to create and apply styles through programming in android?

让人想犯罪 __ 提交于 2019-12-24 08:23:46

问题


I am new to Android app. development. I need to change the existing style at runtime or can create new styles at runtime and I need to apply it for my buttons and textviews..

Can any one suggest me?


回答1:


There are several methods to do so (most of them are provided by the super class TextView):

  • setTextColor to change the color of foreground
  • setTypeface to change the font style
  • setBackgroundResource(int) to change its backgrond
  • setPadding to add padding

All of them work for EditText, Button and others, since most of them extends the TextView class. So, my suggestion is: RTFM... just kidding... read the documentation to see the available functions.




回答2:


Yesterday I was trying to do something similar. This links gave me enough info:

  • Building Custom Components
  • Custom Android Button Style and Theme
  • Understanding Android Themes And Styles


来源:https://stackoverflow.com/questions/3074041/how-to-create-and-apply-styles-through-programming-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!