当前位置:  编程技术>移动开发
本页文章导读:
    ▪自定义 Theme 改变 系统大局样式        自定义 Theme 改变 系统全局样式 转自:http://www.androidworks.com/changing-the-android-edittext-ui-widget Changing the Android EditText UI Widget Summary: This article should be useful to people who want to customize the default UI EditTe.........
    ▪ Frame卡通片        Frame动画   本例完全参照androidAPI文档上面来写的,哈哈。  步骤:  1. 在res目录下的drawable目录下创建frame-by-frame animation xml文件。  2. 在这个xml文件中只有两个元素,一个是<animation-list.........
    ▪ Animation(2)       Animation(二)   本篇介绍如何用配置文件进行控件的动画设置。步骤如下:  1. 在res目录下建立anim目录  2. 在anim目录下创建动画的xml文件  3. 通过AnimationUtils这个类加载动画的xml文件  4..........

[1]自定义 Theme 改变 系统大局样式
    来源: 互联网  发布时间: 2014-02-18
自定义 Theme 改变 系统全局样式
转自:http://www.androidworks.com/changing-the-android-edittext-ui-widget
Changing the Android EditText UI Widget
Summary:
This article should be useful to people who want to customize the default UI EditText as well as TextView on the Android platform.  Mostly, I mean the Orange skin that appears to be hard to change.  No matter how many color properties I attempted, I failed.  Then, after inspecting the Android source code, picking apart how they wrote the TextView control (which EditText extends), I realized it was just a skin of NinePatchdrawables set in the background of the underlying View class.  I’ll take you through the steps.

Some background on how it works:
First lets look at the art that Android uses, and how they reference it.  This provides a better understanding of what we need to do on our own.

Look in the <android_sdk>\platforms\android-x.x\data\res\drawable directory.  In this directory, you will notice this file, edit_text.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false" android:state_enabled="true" android:drawable="@drawable/textfield_default" />
  <item android:state_window_focused="false" android:state_enabled="false" android:drawable="@drawable/textfield_disabled" />
  <item android:state_pressed="true" android:drawable="@drawable/textfield_pressed" />
  <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_selected" />
  <item android:state_enabled="true" android:drawable="@drawable/textfield_default" />
  <item android:state_focused="true" android:drawable="@drawable/textfield_disabled_selected" />
  <item android:drawable="@drawable/textfield_disabled" />
</selector>This is the ColorStateList that is default for the EditText background.  This file points to various background resources in each state.  So, from inspection, it appears that we need to create NinePatch art for the following drawable files:

textfield_default.9.png, textfield_disabled.9.png, textfield_pressed.9.png, textfield_selected.9.png, textfield_disabled_selected.9.png, etc…

            
So, this is where and how Android’s default EditText gets the Orange look!

Create your own NinePatch skins:
So change the look to your requirements (using gimp, photoshop, or Android’s recommended Draw9Patch tool), in my case I just did a red version of these files.  Place these new png’s in your res/drawable directory.  Now they can be referenced by your very own ColorStateList.

Name them .9.png

      
Create your new ColorStateList
Using the example provided by the default Android edit_text.xml above, create your own version of it, pointing to your own NinePatch files.  This file should live in your res/drawable directory also.  Now you have a valid ColorStateList visible to styles and widgets.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/textfield_default" />
  <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/textfield_disabled_red" />
  <item android:state_pressed="true" android:drawable="@drawable/textfield_pressed_red" />
  <item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/textfield_selected_red" />
  <item android:state_enabled="true" android:drawable="@drawable/textfield_default" />
  <item android:state_focused="true" android:drawable="@drawable/textfield_disabled_selected_red" />
  <item android:drawable="@drawable/textfield_disabled_red" />
</selector>Save it as red_edit_text.xml and place in your res/drawable directory.

Point you EditText background to the ColorStateList
In my case, decided to use a theme and style approach to override all EditText boxes in my Application.

From my AndroidManifest.xml application element, set the theme

android:theme="@style/mytheme"From my theme.xml

<resources>
<style name="mytheme" parent="@android:style/Theme" >
<item name="android:editTextStyle">@style/red_edittext</item>
</style>
</resources>
From my styles.xml

<resources>
<style name="red_edittext" parent="@android:style/Widget.EditText">
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:clickable">true</item>
<item name="android:background">@drawable/red_edit_text</item>
<item name="android:textColor">@color/state_list</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textColorHint">@color/default_text_color</item>
<item name="android:textColorHighlight">@color/transparent_red</item>
</style>
<style name="droiddate_btn" parent="@android:style/Widget.Button">
<item name="android:background">@drawable/btn_default_red</item>
</style>
</resources>Results:
So now all EditText boxes should have my new red color instead of the default Orange.  Although this might not be your end goal, just to change an EditText box from orange to red, it allows you to see how Android NinePatch, ColorStateList , Styles, and Themes can all work together to override and skin any control in Android.  It could obviously be much more dramatic than my example below.  Good luck, here is the result:



Please feel free to comment,
Marcus Williford

mwilliford@androidworks.com

Tags: Android, Android UI, ColorStateList, EditText, Style, Theme

    
[2] Frame卡通片
    来源: 互联网  发布时间: 2014-02-18
Frame动画
  本例完全参照androidAPI文档上面来写的,哈哈。
  步骤:
  1. 在res目录下的drawable目录下创建frame-by-frame animation xml文件。
  2. 在这个xml文件中只有两个元素,一个是<animation-list>,另一个<item>,意思一目了然,这里不多解释了。
  3. 为控件设置backgroundResource
  4. 获取background,并转换成AnimationDrawable
  5. 调用AnimationDrawable的start方法来启动动画
  话不多说,代码如下:
 
package com.kevin.frame;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class FrameDemo extends Activity {
	private ImageView img;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        img = (ImageView)findViewById(R.id.imageView1);
        // 设置控件的背景资源
        img.setBackgroundResource(R.drawable.dance);
        img.setOnClickListener(new ImgOnClickListner());
    }
    
    class ImgOnClickListner implements OnClickListener{

		@Override
		public void onClick(View v) {
			// 获取背景,并转换成AnimationDrawable
			AnimationDrawable frameAnimation = (AnimationDrawable)img.getBackground();
			// 启动动画
			frameAnimation.start();
		}
    	
    }
}

    
[3] Animation(2)
    来源: 互联网  发布时间: 2014-02-18
Animation(二)
  本篇介绍如何用配置文件进行控件的动画设置。步骤如下:
  1. 在res目录下建立anim目录
  2. 在anim目录下创建动画的xml文件
  3. 通过AnimationUtils这个类加载动画的xml文件
  4. 给你需要的控件绑定Animation
  话不多说,代码如下:
 
package com.kevin.animation;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

public class AnimationDemo extends Activity {
	private ImageView img;
	private int flag = 0;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        img = (ImageView)findViewById(R.id.imageView1);
        img.setOnClickListener(new ImgOnClickListenr());
    }
    
    class ImgOnClickListenr implements OnClickListener{

		@Override
		public void onClick(View v) {
			switch (flag) {
			case 0:
				// 加载动画的配置文件
				Animation alphaAnimation = AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.alpha);
				// 调用animation
				img.startAnimation(alphaAnimation);
				flag++;
				break;
			case 1:
				Animation rotateAnimation = AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.rotate);
				img.startAnimation(rotateAnimation);
				flag++;
				break;
			case 2:
				Animation scaleAnimation = AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.back_scale);
				img.startAnimation(scaleAnimation);
				flag++;
				break;
			case 3:
				Animation translateAnimation = AnimationUtils.loadAnimation(AnimationDemo.this, R.anim.translate);
				img.startAnimation(translateAnimation);
				flag = 0;
			default:
				break;
			}
		}
    	
    }
}
  

这里举个配置文件说明一下,代码如下:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
	<scale android:fromXScale="0.0"
		   android:toXScale="1.0"
		   android:fromYScale="1.0"
		   android:toYScale="1.0"
		   android:pivotX="50%"
		   android:pivotY="50%"
		   android:duration="5000"/>	   
</set>

  注意这边的piovtX属性后面跟的值,因为scale缩放时,轴心的位置相对于控件的位置有三种:
  1. 当你写50时,它是采用的absolute去取轴心的位置
  2. 当你写50%时,它是采用的RELATIVE_TO_SELF去取轴心的位置
  3. 当你写50%p时,它是采用的RELATIVE_TO_PARENT去取轴心的位置
好了就写到这里吧。

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3