您的位置:首页 > 其它

学习xml文件小结

2015-06-15 09:27 162 查看
大家都知道安卓的xml文件很容易写,我就想怎么用java代码写出这样的效果呢,怎么把它转换成java代码在主程序里实现呢,下面是我学习时总结的一两点小知识:

首先我们得把资源从xml中引用出来:

Resources res = getResources();// 系统资源引用方法

String str = res.getString(R.string.hello_android);//hello_android是要引用的资源标签

System.out.println("str>>>" + str);// 在LogCat里打印出来,看看打印结果就知道引用效果了。

下面是我写的一个小Demo的一段java代码:

Resources res = getResources();// 系统资源引用方法

String str = res.getString(R.string.hello_android);

System.out.println("str>>>" + str);// 在LogCat里打印出来

TextView textView = new TextView(this);

textView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,

LayoutParams.WRAP_CONTENT));

textView.setTextColor(getResources().getColor(

android.R.color.holo_green_light));

textView.setText(str);

textView.setSingleLine(true);

textView.setEllipsize();

textView.setMarqueeRepeatLimit();

textView.setMovementMethod(ScrollingMovementMethod.getInstance());

setContentView(textView);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: