[3] use of the Injection framework RoboGuice: (Your First Resource Injection) and roboguiceinjection
In the previous article, we briefly introduced the use of RoboGuice ([2] use of the Injection framework RoboGuice :( Your First View Injection). Today, let's take a look at the method of using annotations for resource files:
To use annotations for Chinese source files in an Activity, you must perform the following two steps:
①: Create an Activity that inherits the RoboActivity
②: Use @ InjectResource to annotate resource files
Below we will implement the following. Now we have an Animation file my_animation.xml under the res/anim directory. Then we use @ InjectResource to get the Animation object.
public class MyActivity extends RoboActivity { @InjectResource(R.anim.my_animation) Animation myAnimation; // the rest of your code}
This is simple. Now you can directly use the myAnimation object. In addition to animation, we also use annotations to use any types of resource files, such as strings, drawables, and animations.
@ ContentView (R. layout. activity_main) public class MainActivity extends RoboActivity {@ InjectView (R. id. TV _one) TextView mTextView_one; @ InjectView (R. id. img_one) ImageView mImage_one; @ InjectResource (R. string. app_name) String mString; @ InjectResource (R. anim. animation_rotale_layout) Animation mAnimation; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); // sets the text mTextView_one.setText (mString); // sets the image animation mImage_one.startAnimation (mAnimation );}
Instance code and libs directory support package download: http://download.csdn.net/detail/jiangqq781931404/8079951