标签:
-------------------xml文件内容------------------------
res/animator/property_animator.xml:
<set android:ordering="sequentially">
<set>
<objectAnimator
android:propertyName="x"
android:duration="500"
android:valueTo="400"
android:valueType="intType"/>
<objectAnimator
android:propertyName="y"
android:duration="500"
android:valueTo="300"
android:valueType="intType"/>
</set>
<objectAnimator
android:propertyName="alpha"
android:duration="500"
android:valueTo="1f"/>
</set>
----------------------Java客户代码------------------------------
AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(myContext,
R.anim.property_animator);
set.setTarget(myObject);
set.start();-------------------xml文件内容------------------------
res/anim/rocket.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
----------------------Java客户代码------------------------------
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();-------------------xml文件内容------------------------
res/drawable/layers.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/android_red"
android:gravity="center" />
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/android_green"
android:gravity="center" />
</item>
<item android:top="20dp" android:left="20dp">
<bitmap android:src="@drawable/android_blue"
android:gravity="center" />
</item>
</layer-list>
----------------------客户代码------------------------------
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="@drawable/layers" />
-------------------xml文件内容------------------------
res/drawable/button.xml:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:state_hovered="true"
android:drawable="@drawable/button_focused" /> <!-- hovered -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
----------------------客户代码------------------------------
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/button" /><?xml version="1.0" encoding="utf-8"?>
<level-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/status_off"
android:maxLevel="0" />
<item
android:drawable="@drawable/status_on"
android:maxLevel="1" />
</level-list>-------------------xml文件内容------------------------
res/drawable/gradient_box.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#FFFF0000"
android:endColor="#80FF00FF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>
----------------------客户代码------------------------------
<TextView
android:background="@drawable/gradient_box"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />-------------------xml文件内容------------------------
res/menu/example_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/item1"
android:title="@string/item1"
android:icon="@drawable/group_item1_icon"
android:showAsAction="ifRoom|withText"/>
<group android:id="@+id/group">
<item android:id="@+id/group_item1"
android:onClick="onGroupItemClick"
android:title="@string/group_item1"
android:icon="@drawable/group_item1_icon" />
<item android:id="@+id/group_item2"
android:onClick="onGroupItemClick"
android:title="@string/group_item2"
android:icon="@drawable/group_item2_icon" />
</group>
<item android:id="@+id/submenu"
android:title="@string/submenu_title"
android:showAsAction="ifRoom|withText" >
<menu>
<item android:id="@+id/submenu_item1"
android:title="@string/submenu_item1" />
</menu>
</item>
</menu>
----------------------Java客户代码------------------------------
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.example_menu, menu);
return true;
}
public void onGroupItemClick(MenuItem item) {
// One of the group items (using the onClick attribute) was clicked
// The item parameter passed here indicates which item it is
// All other menu item clicks are handled by onOptionsItemSelected()
}-------------------xml文件内容-----------------------
res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello!</string>
</resources>
----------------------客户代码------------------------------
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />-------------------xml文件内容-----------------------
res/values/strings.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="planets_array">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
</string-array>
</resources>
----------------------Java客户代码------------------------------
Resources res = getResources();
String[] planets = res.getStringArray(R.array.planets_array);-------------------xml文件内容-----------------------
res/values-small/bools.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<bool name="screen_small">true</bool>
<bool name="adjust_view_bounds">true</bool>
</resources>
----------------------Java客户代码------------------------------
Resources res = getResources();
boolean screenIsSmall = res.getBoolean(R.bool.screen_small);
----------------------客户代码------------------------------
<ImageView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/logo"
android:adjustViewBounds="@bool/adjust_view_bounds" />-------------------xml文件内容-----------------------
res/values/colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="opaque_red">#f00</color>
<color name="translucent_red">#80ff0000</color>
</resources>
----------------------Java客户代码------------------------------
Resources res = getResources();
int color = res.getColor(R.color.opaque_red);
----------------------客户代码------------------------------
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/translucent_red"
android:text="Hello"/>-------------------xml文件内容-----------------------
res/values/dimens.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="textview_height">25dp</dimen>
<dimen name="textview_width">150dp</dimen>
<dimen name="ball_radius">30dp</dimen>
<dimen name="font_size">16sp</dimen>
</resources>
----------------------Java客户代码------------------------------
Resources res = getResources();
float fontSize = res.getDimension(R.dimen.font_size);
----------------------客户代码------------------------------
<TextView
android:layout_height="@dimen/textview_height"
android:layout_width="@dimen/textview_width"
android:textSize="@dimen/font_size"/>-------------------xml文件内容-----------------------
res/values/integers.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="max_speed">75</integer>
<integer name="min_speed">5</integer>
</resources>
----------------------Java客户代码------------------------------
Resources res = getResources();
int maxSpeed = res.getInteger(R.integer.max_speed);-------------------xml文件内容-----------------------
res/values/integers.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer-array name="bits">
<item>4</item>
<item>8</item>
<item>16</item>
<item>32</item>
</integer-array>
</resources>
----------------------Java客户代码------------------------------
Resources res = getResources();
int[] bits = res.getIntArray(R.array.bits);-------------------xml文件内容-----------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomText" parent="@style/Text">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#008</item>
</style>
</resources>
----------------------客户代码------------------------------
<?xml version="1.0" encoding="utf-8"?>
<EditText
style="@style/CustomText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello, World!" />res/values/styles.xml
<declare-styleable name="custom_attrs">
<attr name="custom_color1" format="color"></attr>
<attr name="custom_color2" format="color"></attr>
<attr name="custom_color3" format="color"></attr>
<attr name="custom_color4" format="color"></attr>
<attr name="custom_color5" format="color"></attr>
</declare-styleable>
<attr name="custom_style" format="reference"></attr>res/layout/mylayout.xml
<com.exmp.MyCustomView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:style="@style/myStyle"
app:custom_color1="#ff000000"
>
</com.exmp.MyCustomView>
res/values/styles.xml
<style name="myStyle">
<item name="custom_color1">#ff111111</item>
<item name="custom_color2">#ff111111</item>
</style>res/values/styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
//配置style
<item name="custom_style">@style/custom_theme</item>
//直接在主题中指定
<item name="custom_color1">#ff444444</item>
<item name="custom_color2">#ff444444</item>
<item name="custom_color3">#ff444444</item>
<item name="custom_color4">#ff444444</item>
<item name="custom_color5">#ff444444</item>
</style>
res/values/styles.xml
<style name="custom_theme">
<item name="custom_color1">#ff222222</item>
<item name="custom_color2">#ff222222</item>
<item name="custom_color3">#ff222222</item>
</style><style name="default_style">
<item name="custom_color1">#ff333333</item>
<item name="custom_color2">#ff333333</item>
<item name="custom_color3">#ff333333</item>
<item name="custom_color4">#ff333333</item>
</style>public MyCustomView(Context context) {
this(context,null);
}
public MyCustomView(Context context, AttributeSet set) {
this(context, set, R.attr.custom_style); //对应PartB
}
public LinearRecyclerView(Context context, AttributeSet set, int defStyle) {
super(context, set, defStyle);
final TypedArray a = context.obtainStyledAttributes(
set, R.styleable.custom_attrs, defStyle, R.style.default_style); //对应PartC
}标签:
原文地址:http://blog.csdn.net/evan_man/article/details/51615568