</ style >
@drawable/filled_box:资源文件中新建drawable文件夹,新建filled_box样式xml
代码
< shape xmlns:android =“http://schemas.android.com/apk/res/android” >
< solid android:color ="#f0600000" />
< stroke android:width =“3dp” color ="#ffff8080" />
< corners android:radius =“3dp” />
< padding android:left =“10dp” android:top =“10dp”
android:right =“10dp” android:bottom =“10dp” />
</ shape >
(2)Manifest.xml中配置Acitivity样式
代码
< activity android:name =".Main"
android:label ="@string/app_name"
android:theme ="@android:style/Theme.Dialog" >
< intent-filter >
< action android:name =“android.intent.action.MAIN” />
< category android:name =“android.intent.category.LAUNCHER” />
</ intent-filter >
</ activity >
(3)为Activity设置图标
代码
// 设定窗口模式(仿Dialog中的icon,带有一个左图标)
requestWindowFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.main);
// 设置图片资源
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON
, R.drawable.icon);
9、从一个Activity1到另一个Activity2,当在第二个Activity2按返回键不出现Activity1的做法是在打开Activity2的同时关闭
Activity1
Intent intent = new Intent(Main. this , fowardwidget. class );
startActivity(intent);
finish();
10、允许TextView的文本值拼接
(1)允许在TextView的文本值后添加buffer text
tv.setText(tv.getText(),TextView.BufferType.EDITABLE);
(2)使用Editable对象添加buffer text
Editable text= (Editable)tv.getText();
text.append( " editable " );
text.append(
" /n " ):
11、如果历史栈中包含Activity,打开此Activity从栈中放到栈顶层而不是从新打开Activity
Intent intent = new Intent(ReorderFour. this , ReorderTwo. class );
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);
12、避免输入法面板遮挡,在manifest.xml中activity中设置android:windowSoftInputMode
android:windowSoftInputMode=“stateVisible|adjustResize”
13、获取当前手机壁纸和设置手机壁纸(wallpaper)
(1)获取当前壁纸
WallpaperManager wm=WallpaperManager.getInstance(this);
Drawable wallpaper=wpm.getDrawable();
(2)设置当前壁纸,同时要添加壁纸设置权限
imapaper.setDrawingCacheEnabled(true);
Drawable drawale=this.getResources().getDrawable(R.drawable.bg);
imapaper.setImageDrawable(drawale);
wpm.setBitmap(imapaper.getDrawingCache());
< uses-permission android:name =“android.permission.SET_WALLPAPER” ></ uses-permission >
14、常见通过系统服务得到的实例化对象
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
15、检查网络是否连接
代码
// 检查网络是否连接
public boolean checkIntent(){
ConnectivityManager mannager = (ConnectivityManager)
this .getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo info = mannager.getActiveNetworkInfo();
if (info == null || ! info.isConnected()){
return false ;
}
if (info.isRoaming()){
return true ;
}
return true ;
}
< uses-permission android:name =“android.permission.ACCESS_NETWORK_STATE” ></ uses-permission >
16、从资源文件中(asset)读取文本文档
// 获得输入流
InputStream in = getAssets().open( " read_asset.txt " );
int size = in.available();
ssion android:name =“android.permission.ACCESS_NETWORK_STATE” ></ uses-permission >
16、从资源文件中(asset)读取文本文档
// 获得输入流
InputStream in = getAssets().open( " read_asset.txt " );
int size = in.available();