android 资源使用

来源:互联网 发布:php 获取视频预览图 编辑:程序博客网 时间:2024/06/07 05:59

下面是一些好的和不好的代码例子:

// Load a background for the current screen from a drawable resource.

this.getWindow().setBackgroundDrawableResource(R.drawable.my_background_image);

 

// WRONG Sending a string resource reference into a

// method that expects a string.

this.getWindow().setTitle(R.string.main_title);

 

// RIGHT Need to get the title from the Resources wrapper.

this.getWindow().setTitle(Resources.getText(R.string.main_title));

 

// Load a custom layout for the current screen.

setContentView(R.layout.main_screen);

 

// Set a slide in animation for a ViewFlipper object.

mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,

        R.anim.hyperspace_in));

 

// Set the text on a TextView object.

TextView msgTextView = (TextView)findViewByID(R.id.msg);

msgTextView.setText(R.string.hello_message);

0 0
原创粉丝点击