Android中去掉自带导航栏
摘要:去掉所有Activity中的导航栏:在AndroidManifest.xml文件中定义 <applicationandroid:theme="@android:style/Theme.NoTitleBar"> 去掉某个Activity中的导航栏:在该Activity的onCreate()方法中添加 requestWindowFeature(Window.FEATURE_NO_TITLE); 本人发布的内容均为学习中用过的代码,上传主要为了方便以后的复习和为他人提供一些方便,一些代码没有上下文,新学的朋友有不懂或存在问题的地方可以留言。
阅读全文
Android中的自动重启功能
摘要:Intenti=getBaseContext().getPackageManager().getLaunchIntentForPackage(getBaseContext().getPackageName());i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);startActivity(i); 本人发布的内容均为学习中用过的代码,上传主要为了方便以后的复习和为他人提供一些方便,一些代码没有上下文,新学的朋友有不懂或存在问题的地方可以留言。
阅读全文
Android中Activity间的跳转
摘要:1、目的Activity要继承Activity:public class twoActivityextends Activity{...}2、myButton.setOnClickListener(new myButtonListener()) ;//按钮捆绑监听器class MyButtonListener implements OnClickListener{ //监听器,覆写OnClickListener //不传值时下面可以简写成:startActivity(new Intent(OneActivity.this, TwoActivity.class)); Intent inte...
阅读全文
Android中的退出菜单
摘要:在Activity.java中覆写onCreateOptionsMenu(Menu)回调函数public boolean onCreateOptionsMenu(Menu menu) { //(菜单组的名字,这项菜单(按钮)的ID,排序,按钮上的内容) 每个按钮对应一个 menu.add(0,1,1,title) return super.onCreateOptionsMenu(Menu);}再覆写onOptionsItemSeleted(MenuIntem)的回调函数public boolean onOptionsItemSeleted(menuIntem item) { //i...
阅读全文
Android中一些布局文件实例
摘要:<LinearLayout //跟标签,布局方式采用线性布局 android:orientation="vertical" //标签方向垂直 android:layout_width="fill_parent" //控制宽度,父控件填满 android:layout_height="fill_parent" //控制高度, > <TextView //文本控件 android:id="@+id/myTextView" //设置控件id android:layout_width="fill
阅读全文
Android中的控件设置信息总结
摘要:android:id //为控件指定IDandroid:text //指定控件显示的文字android:gravity //指定控件当中文字位置,居中"center"、居右(right)等android:textSize //文字大小"XXdp"android:background //背景颜色"#******"android:width //控件宽度,填满父控件(fill_parent)、刚好包含内容(wrap_content)android:height //控件高度android:weight //多个控件是表示所占比例andr
阅读全文
Android中的SQLite数据库
摘要://创建数据库,数据库名称为mydata.dbDatabaseHelper dbHelper = new DatabaseHelper(MyActivity.this, "mydata.db");SQLiteDatabase db = dbHelper.getReadableDatabase();p...
阅读全文
Android中的定时器
摘要:Timer mTimer = new Timer();mTimer.schedule(new TimerTask() { @Override public void run() { //要执行的操作 } }, 5*1000, 10*1000); //调用 schedule() 方法后,要等待5s才第一次执行 run() 方法,之后每隔10s执行一次 //停止定时器mTimer.cancel(); 本人发布的内容均为学习中用过的代码,上传主要为了方便以后的复习和为他人提供一些方便,一些代码没有上下文,新学的朋友有不...
阅读全文
Android中弹出提示框
摘要:AlertDialog.Builder alertbBuilder=new AlertDialog.Builder(当前Activity.this);alertbBuilder.setTitle("提示").setMessage("确认退出?").setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //确定后...
阅读全文
Android中使用GPS时若未打开则跳至GPS设置界面
摘要:LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);//若GPS未打开,跳转到GPS设置页面if (!(locationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER))){ //下面括号内的字符串也可以改为“gps” startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS&q
阅读全文
Android中GPS定位获取当前坐标
摘要:LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);//括号中的0,0分别表示每隔多长时间和每隔多长距离进行一次定位locationManager.requestL...
阅读全文
Android中判断Service是否运行
摘要:if (isServiceStarted(MyCurrentActivity.this, "包名")){ txtStatus.setText("正在运行"); } else{ txtStatus.setText("未运行"); }public static boolean isServiceStarted(Context context,String PackageName){ boolean isStarted =false; try{ int intGetTastCounter = 1000; ActivityManager mA
阅读全文
Android中Service的使用
摘要://启动ServicestartService(new Intent(MyCurrentActivity.this, MyService.class));//停止ServicestopService(new Intent(MyCurrentActivity.this, MyService.class));@SuppressLint("SimpleDateFormat")public class MyGPSService extends Service { private String strLongitude; private String strLatitude; Tim
阅读全文
Android中的日期时间显示
摘要:(一)SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss"); Date curDate = new Date(System.currentTimeMillis()); String time = formatter.format(curDate); (二)final Calendar c = Calendar.getInstance();String time = c.get(Calendar.YEAR)+"年"+c.get(Calendar.MONTH)+&
阅读全文