- 浏览: 222319 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (109)
- IOS (15)
- 设计模式 (7)
- XML (1)
- Android (31)
- 面试经 (1)
- J2EE (3)
- android md5 加密 (2)
- android imagebutton文字实现 (1)
- 反射机制 (2)
- 基础知识 (1)
- linux (3)
- java (4)
- java基础 (2)
- 文章 (1)
- myeclipse tomcat (1)
- Hadoop (1)
- ubuntu (2)
- redmine (1)
- python (4)
- jmeter (10)
- xamarin (1)
- selenium (9)
- nexus (1)
- appium (3)
- BDD (1)
- apache2 (1)
- zabbix (2)
- python,webdriver (1)
- ajax (1)
- jmeter,正则表达式,关联 (2)
- 性能测试工具 (1)
- Django (0)
- Intelij (1)
- RAP (0)
- 性能测试 (0)
最新评论
写程序中可能需要用到一些自定义的view控件,这样就需要增加一些自定义的属性。
比如说我要做个股票报价的TextView,涨是红色,跌是绿色
1。先在values目录下创建styles.xml
<resources>
<style name=" Widget. MyTextView" parent="android:Widget" >
<item name="positiveColor" >#FFFF0000</item>
<item name="negetiveColor" >#FF00FF00</item>
</style>
</resources>
2。上面的步骤完成后,在values目录下创建一个attrs.xml文件,告诉程序你自定义的item是什么类型的
<resources>
<declare-styleable name=" MyTextView" >
<attr name=" positiveColor " format="color" />
<attr name=" negetiveColor " format=" color " />
</declare-styleable>
</resources>
3。在layout设计中引用自定义view并加入style
<com.pan.MyTextView
style="@style/ Widget. MyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
4。activity中读取
int positiveColor;
int negetiveColor;
public MyTextView(Context context, AttributeSet attrs, int defStyle)
{
super (context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TestView, defStyle, 0 );
int n = a.getIndexCount();
for (int i = 0 ; i < n; i++)
{
int attr = a.getIndex(i);
switch (attr)
{
case R.styleable.MyTextView_positiveColor:
positiveColor = a.getColor(attr, Color.RED);
break ;
case R.styleable.MyTextView_negetiveColor:
negetiveColor = a.getColor(attr, Color.Green);
break ;
}
}
比如说我要做个股票报价的TextView,涨是红色,跌是绿色
1。先在values目录下创建styles.xml
<resources>
<style name=" Widget. MyTextView" parent="android:Widget" >
<item name="positiveColor" >#FFFF0000</item>
<item name="negetiveColor" >#FF00FF00</item>
</style>
</resources>
2。上面的步骤完成后,在values目录下创建一个attrs.xml文件,告诉程序你自定义的item是什么类型的
<resources>
<declare-styleable name=" MyTextView" >
<attr name=" positiveColor " format="color" />
<attr name=" negetiveColor " format=" color " />
</declare-styleable>
</resources>
3。在layout设计中引用自定义view并加入style
<com.pan.MyTextView
style="@style/ Widget. MyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
4。activity中读取
int positiveColor;
int negetiveColor;
public MyTextView(Context context, AttributeSet attrs, int defStyle)
{
super (context, attrs, defStyle);
TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.TestView, defStyle, 0 );
int n = a.getIndexCount();
for (int i = 0 ; i < n; i++)
{
int attr = a.getIndex(i);
switch (attr)
{
case R.styleable.MyTextView_positiveColor:
positiveColor = a.getColor(attr, Color.RED);
break ;
case R.styleable.MyTextView_negetiveColor:
negetiveColor = a.getColor(attr, Color.Green);
break ;
}
}
发表评论
-
Starting emulator for AVD 'android' PANIC: Could not open: android
2013-05-21 13:29 1880我的电脑-->属性-->高级-->环境变量。 ... -
eclipse4.2版本下面安装ADT,安装已经完成了,但没有ADT的那个图标显示
2013-05-21 13:26 904如果安装过程没错,直接在Eclipse ->window ... -
Android 打包签名 从生成keystore到完成签名 -
2012-10-30 00:49 916首先,我们需要一个keystore,当然已经有了的话就不用这一 ... -
解决更新并使用最新ADT20不能创建android项目问题
2012-10-18 22:20 1008不知道谷歌又怎么了,每次更新ADT插件就会出现各种各样的问题, ... -
ORACLE分页查询SQL语法
2012-10-18 22:20 1174oracle数据库 --1:无ORDER BY ... -
Activity生命周期
2012-10-18 22:20 1110博客分类: Android 新的activit ... -
布局
2012-10-18 22:21 1054padding:描述控件里面的内容与控件的关机,内边距;有四个 ... -
常用控件:TextView EditView
2012-10-13 13:32 1137TextView 布局: Xml代 ... -
按钮控件
2012-10-13 13:32 1153监听器: 监听器 方法 内容 OnClickList ... -
菜单
2012-10-13 13:31 1075menu键触发 三种形式:普通的option menu;上下 ... -
HttpClient
2012-10-13 13:31 1091在Android开发中我们经常会用到网络连接功能与服务器进行数 ... -
Android 的一些提示框
2012-10-08 00:57 7651.在测试时,如何实现一个提示 可以使用 Toast.ma ... -
Intent的几种用法
2012-10-08 00:57 908下面列出几种Intent的用法 1. 启动一个新的Activ ... -
Android改变窗口标题栏的布局
2012-10-10 23:26 889一、 重点 一般应用的Title都是建立应用时在Androi ... -
android manifest.xml中元素含义
2012-10-08 00:56 797android:allowTaskReparenting 是 ... -
十二个android编程技巧
2012-10-10 23:26 9641.让一个图片透明: Java代码 1. Bitm ... -
Android Phone类分析
2012-10-10 23:26 1200AccelerometerListener:感应 ... -
android控件设置居中方式
2012-10-07 00:16 8424垂直居中 android:layout_centerVert ... -
android TextView属性大全
2012-10-10 23:28 945android:autoLink设置是否当 ... -
Android之使用HTTP的get,post,HttpClient三种方式向服务器端提交文本数据
2012-10-11 00:16 883客户端代码示例: /** * HTTP请求 * ...
相关推荐
关于详解Android应用中DialogFragment的基本用法,大家可以参考下。 1、 概述 DialogFragment在android 3.0时被引入。是一种特殊的Fragment,用于在Activity的内容之上展示一个模态的对话框。典型的用于:展示警告框...
simply add the fonts to your app, replace your views with their Font counterparts, and specify the fonts through attributes, styles and themes. All fonts are referenced into (subdirectories of) the ...
You can customize view, through this attributes * app:ipv_middle_icon - main view icon * app:ipv_highlight_background_color - background color when view is expand * app:ipv_default_backgrou
CircularProgressIndicator Simple but customizable view for displaying progress With custom colors With or without dot ...Since all attributes have default values, you can specify none of them
add the progressview in your layout.xml and set the attributes // style Horizontal // style Circle In the Activity you can also set all of the attributes in activity horizonta
Custom Progress Layout for Android Here is the youtube link XML Definition Attributes to use Use ProgressLayout progressLayout = (ProgressLayout) findViewById(R.id.progressLayout); //Start it ...
在最近的开发工作中,要实现一个调色板的进度条,SeekBar要分成10段显示不同颜色,功夫不负有心人,终于实现了这个功能,下面分享给大家 示例图: 1.自定义SeekBar ...import android.util.AttributeS
在Android项目的开发中会用到NumberPicker组件,但是默认风格的NumberPicker具有一些不灵活的属性,定制起来也比较麻烦,并且缺少一些过渡动效,因此在应用开发时,一般采用自定义的控件来完成选择功能。 控件截图 =...
public void handleTag(boolean open, String tag, Editable output, Attributes attrs) { if(tag.toLowerCase().equals("span")){ if(open){ //开标签,output是空(sax还没读到),attrs有值 for(i
> * 1.The project does not use any image resources, colors of bottle and water can be changed by custom attributes; > * 2.LoadingView will automatically adjust the width and height; 2 How to Use: ...
1,android 如何让自定义dialog的宽度跟屏幕的宽度一样? 在你dialog.show();后面加上 WindowManager windowManager = getWindowManager(); Display display = windowManager.getDefaultDisplay(); WindowManager....
customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER; // 设置点击屏幕Dialog不消失 customProgressDialog.setCanceledOnTouchOutside(false); return customProgressDialog; }...
这是一个Android使用Dialog制作popWindow气泡提示框的源代码例子,气泡提示是主动弹出,您可以通过此源码学习制作气泡view、气泡dialog、气泡显示内容的自定义,获取屏幕的宽和高,一些初始化代码: //设置...
Developers can customize the following attributes (both via XML and programmatically): bar color bar thickness tick height number of ticks connecting line thickness connecting line col
正在学习自定义View的同学,可以看看源码,希望对你们有帮助! 如果你觉得还不错,可以给个star,支持下,谢谢了! 原始图效果 模仿效果 gif png 流程 绘制中心线,用于计算外层多边形各点的坐标 绘制...
Description of Attributes Attributes Format Default Description sidebar_text_color color Color.GRAY Text color of side bar. sidebar_text_size dimension 14sp Text size of side bar. sidebar_...
在Android项目的开发中会用到NumberPicker组件,但是默认风格的NumberPicker具有一些不灵活的属性,定制起来也比较麻烦,并且缺少一些过渡动效,因此在应用开发时,一般采用自定义的控件来完成选择功能。 控件截图 =...
数据库架构 (SQLite) 表类别列名类型类别编号整数名称文本餐桌活动列名类型活动编号整数类别编号整数名称文本启用布尔值表activity_attributes 列名类型activity_attribute_id 整数活动编号整数类型int /* 距离、持
自定义view实现,通过和弦动态的控制歌词滚动实现;