2012年8月23日

Android中的“再按一次返回键退出程序”实现

摘要: 用户退出应用前给出一个提示是很有必要的,因为可能是用户并不真的想退出,而只是一不小心按下了返回键,大部分应用的做法是在应用退出去前给出一个Dialog,我觉得这样不太友好,用户还得移动手指去按dialog中的按钮。个人觉得“再按一次返回键退出程序”是best practice,实现也很简单,直接上代码:privatelongexitTime=0;@OverridepublicbooleanonKeyDown(intkeyCode,KeyEventevent){if(keyCode==KeyEvent.KEYCODE_BACK&&event.getAction()==KeyEve 阅读全文

posted @ 2012-08-23 22:46 jxgxy 阅读(61168) 评论(7) 推荐(7) 编辑

android 改变文字的大小和字体

摘要: 先在 assets 目录中新建 fonts 目录,然后把字体文件拷进去,我以"汉仪柏青体简"为例。设置代码: TextViewtxtView=(TextView)findViewById(R.id.textView1);txtView.setTypeface(Typeface.createFromAsset(getAssets(),"fonts/haiyiboqingti.ttf"));txtView.setTextSize(30);txtView.setText("我是刘一手,Helloworld.");效果如下: 阅读全文

posted @ 2012-08-23 16:56 jxgxy 阅读(1462) 评论(0) 推荐(0) 编辑

android AlertDialog显示错误 Unable to add window token null is not for an application解决办法

摘要: publicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);findViewById(R.id.button1).setOnClickListener(newButton.OnClickListener(){publicvoidonClick(Viewv){newAlertDialog.Builder(getApplicationContext()).setTitle(R.string.dialogTitle).set 阅读全文

posted @ 2012-08-23 11:47 jxgxy 阅读(16379) 评论(0) 推荐(1) 编辑

android 获取所有传感器数据

摘要: main.xml<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><Te 阅读全文

posted @ 2012-08-23 10:41 jxgxy 阅读(11952) 评论(2) 推荐(0) 编辑

导航