package org.ourunix.android.textviewcode;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class TextViewCodeActivity extends Activity {
/** Called when the activity is first created. */
private LinearLayout mLayout;
private TextView mTextView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 创建一个线性布局
mLayout = new LinearLayout(this);
// 接着创建一个TextView
mTextView = new TextView(this);
// 第一个参数为宽的设置,第二个参数为高的设置。
mTextView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// 设置mTextView的文字
mTextView.setText("这是我的TextView");
// 设置字体大小
mTextView.setTextSize(20);
// 设置背景
mTextView.setBackgroundColor(Color.BLUE);
// 设置字体颜色
mTextView.setTextColor(Color.RED);
// 将TextView添加到Linearlayout中去
mLayout.addView(mTextView);
// 展现这个线性布局
setContentView(mLayout);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
其实在Android中,使用控件除了在layout下的布局文件中实现之外,我们还可以通过在java文件中完全通过编码来实现,只不过完全使用编码的方式来驾驭我们的控件是不可取的,因为这增加了代码量,对外阅读不是太友好,一般的做法是在布局文件中布局某个控件,并使用id来标识,然后在编码中通过提取该id的方法来控制,下面将介绍之。详细见:http://www.ourunix.org/android/post/4.html
资源推荐
资源详情
资源评论
收起资源包目录
TextViewCode.7z (25个子文件)
TextViewCode
bin
classes.dex 3KB
JNITest.apk 13KB
TextViewCode.apk 13KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
drawable-mdpi
ic_launcher.png 2KB
classes
org
ourunix
android
textviewcode
TextViewCodeActivity.class 1KB
R$layout.class 436B
R$drawable.class 449B
R$attr.class 382B
R.class 573B
R$string.class 469B
resources.ap_ 10KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
values
strings.xml 190B
drawable-mdpi
ic_launcher.png 3KB
layout
main.xml 398B
assets
gen
org
ourunix
android
textviewcode
R.java 661B
proguard.cfg 1KB
src
org
ourunix
android
textviewcode
TextViewCodeActivity.java 1KB
.project 848B
.classpath 364B
project.properties 361B
AndroidManifest.xml 790B
共 25 条
- 1
资源评论
- navy8409072012-12-28不错。还行。对初学者很不错
Lorinnn
- 粉丝: 37
- 资源: 47
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功