造型全部TextViews(或自定义视图),而不添加样式属性的每一个的TextView [英] Styling all TextViews(or custom view) without adding the style attribute to every TextView

查看:100
本文介绍了造型全部TextViews(或自定义视图),而不添加样式属性的每一个的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来格式化所有TextViews,按钮或任何一个主题? 就像在CSS时,我想格式化所有的A-标签

Is there a way to format all TextViews, Buttons or whatever with a theme ? Like in CSS when i want to format all a-tags

A { / 一些CSS这里的/ }

a{ /some css here/ }

我想这样做,在Android中通过XML,当我申请一个主题,以我的申请。 任何想法?谢谢

I want to do that in android via xml when I'm applying a theme to my application. Any ideas ?Thanks

http://bartinger.at/

更新1.0: 我想创建一个主题,格式在所有TextViews绿色和所有EditTexts红色的文字。所以,我只是应用的主题,我从来没有担心样式属性!

Update 1.0: I want to create a theme that formats the text in all TextViews green and in all EditTexts red. So that i just apply the theme and I never have to worry about the style attribute!

更新1.1: 所以,我发现了一些那块code,我认为这是一个良好的开端

Update 1.1: So I found some that piece of code and I think that's a good beginning

<item name="android:textViewStyle">@style/MyTextView</item>
<item name="android:buttonStyle">@style/MyButton</item>

我认为,多数民众赞成在回答我的问题。但我有一个又一个。我想写我自己的动作条,想知道我可以应用默认样式或默认属性(同样没有添加样式属性在布局的xml:P)

I think thats the answer to my question. But I have another one. I want to write my own ActionBar and wanted to know how I can apply a default style or default attributes (again without adding the style attribute in the layout xml :P )

我有一个类

public class ActionBar extends LinearLayout{ }

和我会用它一样,在我的应用程序

and I'm gonna use it like that in my application

<at.bartinger.uil.ActionBar>....</at.bartinger.uil.ActionBar>

在动作条应该有一些默认的属性(如高度和宽度),然后加入一些自定义样式属性,它可以从应用程序切换到应用程序(如背景)

The ActionBar should have some default attributes (like height and width) and then adding some custom style attributes which could change from app to app (like background)

推荐答案

是的,你可以,你可以将主题应用到整个应用程序,然后你所有的textviews将有风格。

yes you can you can apply a theme to the whole application and then all your textviews will have that style.

在里面你必须定义你的CustomTheme的styles.xml文件

Inside the styles.xml file you have to define your CustomTheme

例如:

<style name="CustomTheme" parent="android:Theme.Light">
  <item name="android:windowBackground">@color/custom_theme_color</item>
  <item name="android:colorBackground">@color/custom_theme_color</item>
</style>

您加入类似文字     机器人:TEXTSTYLE =myStyle的,并在myStyle的指定信息

you add something like text "android:textStyle="myStyle" and specify the details in Mystyle

这篇关于造型全部TextViews(或自定义视图),而不添加样式属性的每一个的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆