如何让我自己定义的属性值中,我的风格我的、让我、属性、定义

由网友(说不出的疼)分享简介:我要创建3个不同的主题,使用自定义的(自己)属性的对话框。我想加入到这个主题的风格,设置标题颜色:<项目名称=titleColor>#FF0000< /项目> 我的themes.xml:< XML版本=1.0编码=UTF-8&GT?;<资源><样式名称=MyTh...

我要创建3个不同的主题,使用自定义的(自己)属性的对话框。 我想加入到这个主题的风格,设置标题颜色: <项目名称=titleColor>#FF0000< /项目>

我的themes.xml:

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
<样式名称=MyTheme的父=@安卓风格/主题>
    <项目名称=机器人:alertDialogStyle> @风格/对话框< /项目>
< /风格>
<样式名称=MyRedTheme父=MyTheme的>
    <项目名称=titleColor>#FF0000< /项目>
< /风格>
<样式名称=MyGreenTheme父=MyTheme的>
    <项目名称=titleColor>#00FF00< /项目>
< /风格>
<样式名称=MyBlueTheme父=MyTheme的>
    <项目名称=titleColor>#0000FF< /项目>
< /风格>
 

在attrs.xml

我定义titleColor属性:

 < XML版本=1.0编码=UTF-8&GT?;
<资源>
 <申报,设置样式名称=MyCustomAttributes>
  < attr指示NAME =titleColor格式=色|引用/>
 < /申报,设置样式>
< /资源>
 

我申请的主题对话之一。 我怎样才能把我的titleColor属性的值,以一个机器人:色?属性

 < XML版本=1.0编码=UTF-8&GT?;
<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       的xmlns:定制=htt​​p://schemas.android.com/apk/res/com.dicare
   机器人:形状=矩形>
       [固体机器人:颜色=我想通过titleColor价值在这里/>
< /形状>
 
如何在页面上使用图表报告

解决方案

?titleColor see这里

您会定义颜色的colors.xml文件中引用它们像一个正常的资源:@​​彩色/ MyRed

您会成为您希望从布局XMLS定制你自己的看法自定义属性。例如,您可以延长的TextView写文本的第一行中的一种颜色(titleColor)比文本(机器人:文字颜色)的其余部分。

 <颜色名称=MyRed>#FF0000< /彩色>

<样式名称=MyRedTheme父=MyTheme的>
    <项目名称=titleColor> @色/ MyRed< /项目>
< /风格>

<形状的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
       的xmlns:定制=htt​​p://schemas.android.com/apk/res/com.dicare
   机器人:形状=矩形>
       [固体机器人:颜色=@色/ MyRed/>
< /形状>
 

I want to create 3 different themes for a dialog using a custom (own) attribute. I would like to set title colors by adding this to theme's style: <item name="titleColor">#FF0000</item>

my themes.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="@android:style/Theme">
    <item name="android:alertDialogStyle">@style/dialog</item>
</style>
<style name="MyRedTheme" parent="MyTheme">
    <item name="titleColor">#FF0000</item>
</style>
<style name="MyGreenTheme" parent="MyTheme">
    <item name="titleColor">#00FF00</item>
</style>
<style name="MyBlueTheme" parent="MyTheme">
    <item name="titleColor">#0000FF</item>
</style>

I defined titleColor attribute in attrs.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <declare-styleable name="MyCustomAttributes">
  <attr name="titleColor" format="color|reference" />
 </declare-styleable>
</resources>

I apply one of the themes for the dialog. How can I pass my titleColor attribute's value to an "android:color" attribute?

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:custom="http://schemas.android.com/apk/res/com.dicare"
   android:shape="rectangle">
       <solid android:color="I want to pass titleColor value here"/>
</shape>

解决方案

?titleColor see here

or

You'd define your colours in the colors.xml file and reference them like a normal resource: @color/MyRed

You'd make a custom attribute for your own views which you want to be customisable from layout xmls. For example, you might extend TextView to write the first line of text in one colour (titleColor) than the rest of the text (android:textColor).

<color name="MyRed">#FF0000</color>

<style name="MyRedTheme" parent="MyTheme">
    <item name="titleColor">@color/MyRed</item>
</style>

<shape xmlns:android="http://schemas.android.com/apk/res/android"
       xmlns:custom="http://schemas.android.com/apk/res/com.dicare"
   android:shape="rectangle">
       <solid android:color="@color/MyRed"/>
</shape>

阅读全文

相关推荐

最新文章