初学者笔记:
1,网络连接探测:
boolean testNetwork(){
ConnectivityManager manager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo networkinfo = manager.getActiveNetworkInfo();
if (networkinfo == null || !networkinfo.isAvailable()) {
Toast.makeText(this, "No avaliable network", Toast.LENGTH_LONG).show();
return false;
}
return true;
}
2,Anroid Apk自动升级更新
http://blog.csdn.net/xjanker2/article/details/6303937
3,各种控件使用注意:
1),Toast用于提示用户,使用图片的例子
Toast toast = new Toast(this);
ImageView view = new ImageView(this);
view.setImageResource(R.drawable.icon);
toast.setView(view);
toast.show();
使用文字对话框的例子:
Toast toast = Toast.makeText(this, "lalalal", Toast.LENGTH_LONG);
View textView = toast.getView();
LinearLayout lay = new LinearLayout(this);
lay.setOrientation(LinearLayout.HORIZONTAL);
ImageView view = new ImageView(this);
view.setImageResource(R.drawable.icon);
lay.addView(view);
lay.addView(textView);
toast.setView(lay);
toast.show();
2)TabHost中设置标签Tab的高度和宽度
final TabWidget tabWidget = tabHost.getTabWidget();
for (int i =0; i < tabWidget.getChildCount(); i++) {
tabWidget.getChildAt(i).getLayoutParams().height = YOUR_HEIGHT;
tabWidget.getChildAt(i).getLayoutParams().width = YOUR_WEIGHT;
}
注意,如果要是设置的高度和宽度有效,在界面定义文件中TabWidget的布局参数的宽度和高度应设置为 "wrap_content",如
<TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" />
TabHost去掉标签下方的白线:
tabHost.setPadding(tabHost.getPaddingLeft(),
tabHost.getPaddingTop(), tabHost.getPaddingRight(),
tabHost.getPaddingBottom()-5);
也可以修改XML:使用tabStripEnabled
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TabWidget
android:id="@android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:tabStripEnabled="false"...
3),Android字体加粗
在xml文件中使用android:textStyle=“bold”;
但是对中文无效,设置中文为粗体的方法是:
TextView tv = (TextView)findViewById(R.id.TextView01);
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);