android中细节效果总结
andorid取消最上方的标题同时全屏显示
Source code protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //取消最上方的标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splash); //全屏显示 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }整个app取消标题
android:theme=”@android:style/Theme.Translucent.NoTitleBar”
获取版本号
Source code
- private String getVersion() {
- try {
- // getPackageName()得到当前应用包名,当前应用的版本号通过包管理器得到
- PackageInfo info = getPackageManager().getPackageInfo(
- getPackageName(), 0);
- return info.versionName;
- } catch (Exception e) {
- e.printStackTrace();
- return "没得到";
- }
- }
淡入淡出动画效果
Source code
- rl_splash_animation = (RelativeLayout) findViewById(R.id.rl_splash_animation);
- //从完全透明到完全不透明动画效果
- AlphaAnimation a = new AlphaAnimation(0.0f, 1.0f);
- a.setDuration(2000);//动画时间两秒钟
- rl_splash_animation.setAnimation(a);
弹出对话框,下面的代码,是一个升级提醒,仅供参考。
Source code
- /**
- * 升级的对话框
- */
- private void showUpdataDialog() {
- AlertDialog.Builder buider = new Builder(this);
- buider.setIcon(R.drawable.icon5);
- buider.setTitle("升级提醒");
- buider.setMessage(info.getDescription());
- buider.setCancelable(false); // 让用户不能取消对话框
- buider.setPositiveButton("确定", new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Log.i(TAG, "下载apk文件" + info.getApkurl());
- if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){
- DownLoadFileThreadTask task = new DownLoadFileThreadTask(info.getApkurl(), "/sdcard/new.apk");
- pd.show();
- new Thread(task).start();
- }else{
- Toast.makeText(getApplicationContext(), "sd卡不可用", 1).show();
- loadMainUI();
- }
- }
- });
- buider.setNegativeButton("取消", new OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- Log.i(TAG, "用户取消进入程序主界面");
- loadMainUI();
- }
- });
- buider.create().show();
- }
从服务器是获取xml文件,然后解析的一个业务方法
首先传入id这个id是在values里边的一个xml配置文件的id里边是服务器xml文件的地址
然后通过
HttpURLConnection连接服务器,InputStream is = conn.getInputStream();发送请求得到输入流
Source code
- /**
- *
- * @param urlid 服务器路径string对应的id
- * @return 更新的信息
- */
- public UpdataInfo getUpdataInfo(int urlid) throws Exception{
- String path = context.getResources().getString(urlid);
- URL url = new URL(path);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setConnectTimeout(2000);
- conn.setRequestMethod("GET");
- InputStream is = conn.getInputStream();
- return UpdataInfoParser.getUpdataInfo(is);
- }
解析的xml的inputstream,传入xml文件的
inputstream流,读取里边的文件
Source code
- /**
- *
- * @param is
- * 解析的xml的inputstream
- * @return updateinfo
- */
- public static UpdataInfo getUpdataInfo(InputStream is) throws Exception {
- XmlPullParser parser = Xml.newPullParser();
- UpdataInfo info = new UpdataInfo();
- parser.setInput(is, "utf-8");
- int type = parser.getEventType();//定位到文档的开始
- while (type != XmlPullParser.END_DOCUMENT) {//不到末尾
- switch (type) {
- case XmlPullParser.START_TAG:
- if("version".equals(parser.getName())){
- String version = parser.nextText();
- info.setVersion(version);
- }else if("description".equals(parser.getName())){
- String description = parser.nextText();
- info.setDescription(description);
- }else if("apkurl".equals(parser.getName())){
- String apkurl = parser.nextText();
- info.setApkurl(apkurl);
- }
- break;
- }
- type = parser.next();//向下
- }
- return info;
- }
Intent如何传值
Source code
- 案例一
- 传值:
- Intent intent=new Intent();
- intent.putExtra("extra", "这是页面一传来的值!");
- intent.setClass(Test_for_intentActivity.this, actpage2.class);
- startActivity(intent);
- 取值:
- Intent intent=getIntent();
- String StringE=intent.getStringExtra("extra");
- TextView text2=(TextView)findViewById(R.id.textView2);
- text2.setText(StringE);
- 打开网页
- Uri uri = Uri.parse("http://www.google.com");
- Intent it = new Intent(Intent.ACTION_VIEW,uri);
- startActivity(it);
时间: 2024-10-29 19:08:49