android中细节效果总结
2015-12-21 23:39
537 查看
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 |
try {
// getPackageName()得到当前应用包名,当前应用的版本号通过包管理器得到
PackageInfo info = getPackageManager().getPackageInfo(
getPackageName(), 0);
return info.versionName;
} catch (Exception e) {
e.printStackTrace();
return "没得到";
}
}
淡入淡出动画效果
Source code |
//从完全透明到完全不透明动画效果
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);
相关文章推荐
- android EditText 设置密码明文 密文 显示方法
- android布局常用属性记录
- android之ListView,详细介绍实现步骤,举例,自定义listview适配器
- android之保存偏好设置信息到shareSharedPreferences,轻量级的保存数据的方法
- android源码分析之大字体
- android单选按钮选择,RadioGroup,radioButton
- Android sdk开发 - 序
- Android AsyncTask 源码分析
- Android中短信分享功能的实现
- 微软安卓模拟器(Visual Studio Emulator for Android)无法联网解决办法
- Android不用OnScrollListener采用GestureDetector结合OnTouchListener实现ListView下拉/上拉刷新
- Android中连续点击两次BACK键退出程序
- Ubuntu下为AndroidStudio编译并使用FFmpeg(三)源码分析
- android-USB Host
- Ubuntu下为AndroidStudio编译并使用FFmpeg(二)AndroidStudio部分
- Ubuntu下为AndroidStudio编译并使用FFmpeg(一)ndk部分
- 【Android 非常基础】PopupWindow showAtLocation和showAsDropDown参数分析
- Android Volley异步加载图片+缓存策略
- android-Activity读书笔记
- 【Android测试】【第一节】性能——CPU