WEB开发网
开发学院手机开发Android 开发 Android 开发技巧杂集 阅读

Android 开发技巧杂集

 2010-11-05 00:54:42 来源:WEB开发网   
核心提示:1.检查是否有网络连接Java代码1. public static boolean isNetworkAvailable(Context context) {2. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(3. Con

1.检查是否有网络连接

Java代码

1. public static boolean isNetworkAvailable(Context context) {

2. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(

3. Context.CONNECTIVITY_SERVICE);

4. NetworkInfo info = cm.getActiveNetworkInfo();

5. return (info != null && info.isConnected());

6. }

public static boolean isNetworkAvailable(Context context) {

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(

Context.CONNECTIVITY_SERVICE);

NetworkInfo info = cm.getActiveNetworkInfo();

return (info != null && info.isConnected());

}

2.全屏和无标题

Java代码

1. // 全屏 ( No Statusbar )

2. getWindow (). setFlags ( WindowManager . LayoutParams . FLAG _ FULLSCREEN ,

3. WindowManager . LayoutParams . FLAG _ FULLSCREEN );

4. // 无标题栏 ( No Titlebar )

5. requestWindowFeature ( Window . FEATURE _ NO _ TITLE );

// 全屏 ( No Statusbar )

getWindow (). setFlags ( WindowManager . LayoutParams . FLAG _ FULLSCREEN ,

WindowManager . LayoutParams . FLAG _ FULLSCREEN );

// 无标题栏 ( No Titlebar )

requestWindowFeature ( Window . FEATURE _ NO _ TITLE );

3.使用ViewStub延迟展开视图

Java代码

1. 1 ) 定义 ViewStub

2. < ViewStub android : id = "@+ id / stub _ import "

3. android : inflatedId ="@+ id / panel _ import "

4. android : layout ="@ layout / progress _ overlay "

5. android : layout _ width =" fill _ parent "

6. android:layout_height="wrap_content"

7. android:layout_gravity="bottom"/>

8. 2 )展开视图

9. findViewById(R.id.stub_import).setVisibility(View.VISIBLE);

10. // 或者 获取视图

11. View importPanel = ((ViewStub)

1 2 3 4 5 6  下一页

Tags:Android 开发 技巧

编辑录入:coldstar [复制链接] [打 印]
赞助商链接