学习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);
首先我们得把资源从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);
相关文章推荐
- Objective-C Method Swizzling 的最佳实践
- 推荐10本C#编程的最佳书籍
- JS - 事件代理
- Perl图形化包管理工具PPM学习使用笔记
- JAVA操作redis的小demo
- 重识外观模式
- 构建Python包的五个简单准则简介
- 用Curl测试POST
- Cannot find the declaration of element 'beans'
- 常用git命令一览
- hihoCoder挑战赛12 顺子 模拟
- 大话设计模式C++版——工厂模式在COM中的典型应用
- 大话设计模式C++版——工厂模式在COM中的典型应用
- 几道汇编入门题目(二)
- 【互联网+】电子商务秘诀
- 多线程就这么简单 python版
- .NET逻辑分层架构总结
- #为什么TCP/IP需要三次握手#
- 在PC端或移动端应用中接入商业QQ的方法
- PL/SQL Developer 连接Oracle数据库详细配置方法