<TextView>中加上android:autoLink="all", 那么正文中如有网址,是可以被显示成超链接的。或者android:autoLink="web|phone|email"
设置TextView中背景色,背景色在res/value中设置
<drawable name=color_name>color_value</drawable>
Resources resources = getBaseContext().getResources();
Drawable hippoDrawable = resources.getDrawable(R.drawable.white);
在values/strings.xml里定义了默认的字符串常数,需留意遇到如“?”、“ ‘ ”、“\”等符号时,必须使用转义字符(\)
获取手机屏幕分辨率:
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
dm.heightPixels
dm.widthPixels
在Android程序开发过程中,可用样式(style)方式,初始化TextView的一些属性
其中style.xml必须在res/values/style.xml中定义,如
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="text1">
<item name="android:textSize">18dp</item>
</style>
<style name="text2">
<item name="android:textSize">28dp</item>
<item name="android:textColor">#FFF4C4</item>
</style>
</resources>
在res/layout/main.xml引用
style属性
<TextView
style="@style/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:text="@string/hello" />
两个Activity中如果传送数据时,用Bundle,Android.os.Bundle具有对象封装数据的能力。
传数据
Intent intent = new Intent();
intent.setClass(Main.this, Main1.class);
Bundle bundle = new Bundle();
//bundle装入数据程序.. Bundle.putString(string Name,string Value)
intent.putExtras(bundle);//将Bundle对象分配给Intent
startActivity(intent);
接受数据
Bundle bundle = this.getIntent().getExtras()
返回数据到前一个Activity -startActivityForResult方法
Intent intent = new Intent();
intent.setClass(Main.this, Main1.class);
Bundle bundle = new Bundle();
//bundle装入数据程序.. Bundle.putString(string Name,string Value)
intent.putExtras(bundle);//将Bundle对象分配给Intent
startActivityForResult(intent,0);//其中0为下一个Activity返回值的依据,可指定为自行定义的参考标识符
/*覆盖onActivityResult() */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
switch (resultCode) {
case RESULT_OK:
Bundle bundle = data.getExtras();
//接着从bundle里取数据..
break;
default:
break;
}
}
Main1.java中
Intent intent = this.getIntent();
Bundle bundle = intent.getExtras();
Main1.this.setResult(RESULT_OK, intent);//返回result回上一个Activity
Main1.this.finish();//结束这个Activity
控制不同的字体
1.使用setTypeface 2.通过外部资源assets,引用外部字体文件,再通过Typeface类的createFromAsset方法,如 assets/fonts/HandmadeTypewriter.ttf
/*必须事先在assets底下创建一个fonts文件夹,存放要是使用的字体文件(.ttf)*/
text.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf"));
全屏幕以按钮覆盖:核心程序
Button button = new Button(this);//this为现有Activity的Context
this.setContentView(button);
android主题的设置:setTheme()
用EditText.OnKeyListener拦截EditText的键盘输入事件,仅需重写onKey()方法
ImageButton 用setImageResource()改变Button背景图片Toast对象
Toast mToast = new Toast(this);
ImageView mView = new ImageView(this);
mView.setImageResource(R.drawable.ic_launcher);
mToast.setView(mView);
mToast.show();
Toast mToast = new Toast(this);
TextView mView = new TextView(this);
mView.setText("Hello Toast!");
mToast.setView(mView);
mToast.show();
Animation的一些属性:可参考
mTextView.setTextColor(getResource().getColor(R.drawable.blue));
ArrayAdapter的构造器textViewResourceId传入Android.R.layout.simple_list_item_multiple_choice, 代表ListView是可多选的,此时ListView需要setChoiceMode传入ListView,ListView.CHOICE_MODE_MULTIPLE或2,即表示多选功能
从手机存储卡读取图片,用Android API 提供的Bitmap(Android.graphics.Bitmap)与BitmapFactory(Android.graphics.BitmapFactory)对象读取。
Bitmap bm = BitmapFactory.decodeFile(filename);
mImageView.setImageBitmap(bm);
decodeFile()可将手机文件系统的图片文件转换成Bitmap对象,decodeResource()可将/res/drawable/内预先存入的照片文件转换成Bitmap对象,decodeStream()方法可将InputStream转换成Bitmap对象
Matrix(Android.graphic.Matrix)对象的postScale()可以实现手机上图片的缩放功能