




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
0 android 创建按钮Button button = new Button(this);1 android 创建输入框EditText editText = new EditText(this);2 android 创建文本TextView textView = new TextView(this);3 android 设置文本显示内容TextView textView = new TextView(this);textView.setText(hello world!);4 android 设置文本背景色TextView textView = new TextView(this);textView.setBackgroundColor(Color.YELLOW);5 android 设置文本颜色TextView textView = new TextView(this);textView.setTextColor(Color.YELLOW);6 android 设置文本文字大小TextView textView = new TextView(this);textView.setTextSize(18);7 android 设置输入框宽度EditText editText = new EditText(this);editText.setWidth(200);8 android 设置输入框为密码框EditText editText = new EditText(this);editText.setTransformationMethod(PasswordTransformationMethod.getInstance();9 android 设置输入框为密码框(xml配置)android:password=true10 android 提示对话框的使用AlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setTitle(你好);builder.setPositiveButton(OK,this);builder.show()需实现android.content.DialogInterface.OnClickListener接口11 android ListView的使用ListView listView = new ListView(this);ArrayListHashMap list = new ArrayListHashMap();SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,new String标题,new intR.id.TextView01);listView.setAdapter(adapter);listView.setOnItemClickListener(this);然后实现OnItemClickListener接口public void onItemClick(AdapterView parent, View view, int position, long id) 12 android 更新ListViewListView listView = new ListView(this);ArrayListHashMap list = new ArrayListHashMap();SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.list,new String标题,new intR.id.TextView01);listView.setAdapter(adapter);adapter.notifyDataSetChanged();/通知更新ListView13 android 创建LinearLayoutLinearLayout layoutParant = new LinearLayout(this);14 android 时间设置对话框的使用DatePickerDialog dlg = new DatePickerDialog(this,this,year,month,day);dlg.show();/*year month day 均为int型,第二个参数为this时,该类需要implements OnDateSetListener并重写public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) */15 android 创建FrameLayoutFrameLayout layout = new FrameLayout(this);16 android 触发键盘事件layout.setOnKeyListener(this);/需要implements OnKeyListener并重写以下方法public boolean onKey(View v, int keyCode, KeyEvent event) return false;/返回是否销毁该事件以接收新的事件,比如返回true按下时可以不断执行这个方法,返回false则执行一次。17 android 触发鼠标事件layout.OnTouchListener(this);/需要implements OnTouchListener并重写以下方法public boolean onTouch(View v, MotionEvent event) return false;/返回是否销毁该事件以接收新的事件,比如返回true按下时可以不断执行这个方法,返回false则执行一次。18 android 获得屏幕宽度和高度int width = this.getWindow().getWindowManager().getDefaultDisplay().getWidth();int height =this.getWindow().getWindowManager().getDefaultDisplay().getHeight();19 android 布局添加控件LinearLayout layout = new LinearLayout(this);Button button = new Button(this);layout.addView(button);20 android intent实现activit之间跳转Intent intent = new Intent();intent.setClass(this, DestActivity.class);startActivity(intent);21 android intent设置actionIntent intent = new Intent();intent.setAction(intent.ACTION_DIAL);22 android intent设置dataIntent intent = new Intent();intent.setData(Uri.parse(tel:00000000);23 android intent传数据Intent intent = new Intent();intent.putExtra(data, value);/value可以是很多种类型,在接收activity中取出后强制转换或调用相应类型的get函数。24 android intent取数据String value = (String)getIntent().getExtras().get(data);/orString value = getIntent().getExtras().getString(data);25 android 利用paint和canvas画图setContentView(new MyView(this);class MyView extends Viewpublic MyView(Context context)super(context);public void onDraw(Canvas canvas)Paint paint = new Paint();/创建画笔paint.setColor(Color.BLUE);/设置画笔颜色canvas.drawRect(0, 0, 100, 100, paint);/画个正方形,坐标0,0,100,100。26 android 新建对话框Dialog dialog = new Dialog(this);dialog.setTitle(test);/设置标题dialog.addContentView(button,new LayoutParams(-1,-1);/添加控件,-1是设置高度和宽度充满布局,-2是按照需要设置宽度高度。dialog.show();27 android 取消对话框dialog.cancel();28对View类刷新显示view.invalidate();/通过这个调用view的onDraw()函数28 android 对View类刷新显示view.invalidate();/通过这个调用view的onDraw()函数29 android 使用SurfaceView画图setContentView(new MySurfaceView(this);class MySurfaceView extends SurfaceView implements SurfaceHolder.CallbackSurfaceHolder holder;public MySurfaceView(Context context) super(context);holder = getHolder();holder.addCallback(this);class MyThread extends Threadpublic void run()Canvas canvas = holder.lockCanvas();Paint paint = new Paint();paint.setColor(Color.YELLOW);canvas.drawRect(100, 100, 200, 200, paint);holder.unlockCanvasAndPost(canvas);public void surfaceChanged(SurfaceHolder holder, int format, int width,int height) public void surfaceCreated(SurfaceHolder holder) new MyThread().start();public void surfaceDestroyed(SurfaceHolder holder) 30 android 获得控件findViewByIdTextView textView = (TextView) findViewById(R.id.TextView01);31 android 十六进制设置画笔颜色Paint paint = new Paint();paint.setColor(0xffffffff);/第一个ff是透明度的设置。32 android 获得String.xml中配置的字符串/在activity中直接调用getText(R.string.app_name);33 android 去掉应用程序头部requestWindowFeature(Window.FEATURE_NO_TITLE);34 android 使用SharedPreferences写入数据代码getSharedPreferences(data, 0).edit().putString(aa,bb).commit();35 android 使用SharedPreferences读取数据代码String data = getSharedPreferences(data, 0).getString(item,);/后面的是默认值,没有取到则赋值为,如果不想有默认,可以设置null。36 android 继承SQLiteOpenHelperclass MyHelper extends SQLiteOpenHelperpublic MyHelper(Context context, String name, CursorFactory factory,int version) super(context, name, factory, version);public void onCreate(SQLiteDatabase db) db.execSQL(CREATE TABLE IF NOT EXISTS testtable ( +cardno integer primary key, +username varchar, + money integer+);public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)db.execSQL(DROP TABLE IF EXISTS testtable);onCreate(db);37 android 利用SQLiteOpenHelper打开数据库MyHelper dbHelper = new MyHelper(this, testtable.db, null, 1);SQLiteDatabase db = dbHelper.getReadableDatabase();/打开只读/或者SQLiteDatabase db = dbHelper.getWritableDatabase();/打开可写38 android 查询数据表并显示结果Cursor cursor = db.query(testtable, null, null, null, null, null, null);/db的获得请参见“利用SQLiteOpenHelper打开数据库”while(!cursor.isAfterLast()Log.i(test,cursor.getString(0);cursor.moveToNext();39 android Logcat输出打印测试信息Log.i(TAG,TEST);40 android 数据表插入数据ContentValues values = new ContentValues();values.put(username,admin);values.put(money,10000);db.insert(testtable, null, values);41 android 使得应用全屏getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN,WindowManager.LayoutParams. FLAG_FULLSCREEN); 42 android 设置LinearLayout方向为竖layoutParant.setOrientation(LinearLayout.VERTICAL);43 android 设置LinearLayout方向为横layoutParant.setOrientation(LinearLayout.HORIZONTAL);44 android 数据库更新数据ContentValues values = new ContentValues();values.put(username,admin);values.put(money,10000);db.update(testtable,values,userno=1,null);45 android 数据库删除数据db.delete(testtable,userno=1,null);46 android 判断sd卡是否存在if (android.os.Environment.getExternalStorageState().equals( android.os.Environment.MEDIA_MOUNTED)Log.i(test,SDCARD exists);else Log.i(test,SDCARD doesnt exist);47 android 创建ImageViewImageView view = new ImageView(this); view.setImageResource(R.drawable.icon);48 android 提示信息Toast toast = Toast.makeText(this, hello, Toast.LENGTH_LONG); toast.show();49 android 创建单选框以及单选组RadioButton radioButton = new RadioButton(this);RadioButton radioButton2 = new RadioButton(this);radioButton.setText(yes);radioButton2.setText(no);RadioGroup radioGroup = new RadioGroup(this);radioGroup.addView(radioButton);radioGroup.addView(radioButton2);50 android 新建播放器MediaPlayer MediaPlayer = new MediaPlayer();51 android 媒体播放器使用/创建MediaPlayerMediaPlayer player = new MediaPlayer();/重置MediaPlayerplayer.reset();try /设置要播放的文件的路径player.setDataSource(/sdcard/1.mp3);/准备播放player.prepare();catch (Exception e) /开始播放player.start();/设置播放完毕事件player.setOnCompletionListener(new OnCompletionListener()public void onCompletion(MediaPlayer player) /播完一首循环try /再次准备播放player.prepare();catch (Exception e) player.start(););52 android 媒体播放器暂停player.pause();53 android 清空cookiesCookieManager.getInstance().removeAllCookie();54 android 文本设置粗体TextView textView = new TextView(this);TextPaint textPaint = textView.getPaint();textPaint.setFakeBoldText(true);55 android 网络权限配置56 android GL设定背景色gl.glClearColor(0.5f, 0.2f, 0.2f, 1.0f);gl.glClear(GL10.GL_COLOR_BUFFER_BIT);57 android 创建GL画布public class My3DView extends GLSurfaceView private GLSurfaceView.Renderer renderer;public My3DView(Context context) super(context);renderer = new My3DRender();setRenderer(renderer);58 android 创建复选框CheckBox checkBox = new CheckBox(this);59 android 复选框监听选择/取消事件checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) Log.i(QSR,TEST););60 android 创建菜单/重写下面这个函数public boolean onCreateOptionsMenu(Menu menu) super.onCreateOptionsMenu(menu); menu.add(0, 1, 1, test1); menu.add(0, 2, 2, test2); menu.add(0, 3, 3, test3); menu.add(0, 4, 4, test4); return true; 61 android 处理菜单选择事件public boolean onOptionsItemSelected(MenuItem item)int id = item.getItemId();switch (id) case 1:Log.i(QSR,1);break;case 2:Log.i(QSR,2);break;case 3:Log.i(QSR,3);break;case 4:Log.i(QSR,4);break;default:break;return super.onOptionsItemSelected(item); 62 android 允许程序访问GPS(XML配置)63 android 允许程序访问GSM网络信息(XML配置)64 android 允许程序访问WIFI网络信息(XML配置)65 android 允许程序更新电池状态(XML配置)66 android 允许程序写短信(XML配置)67 android 允许程序设置壁纸(XML配置)68 android 允许程序使用蓝牙(XML配置)69 android 允许程序打电话(XML配置)70 android 允许程序使用照相设备(XML配置)71 android 允许程序改变网络状态(XML配置)72 android 允许程序改变WIFI状态(XML配置)73 android 允许程序删除缓存文件(XML配置)74 android 允许程序删除包(XML配置)75 android 允许程序禁用键盘锁(XML配置)76 android 允许程序获取任务信息(XML配置)77 android 允许程序截获鼠标或键盘等事件(XML配置)78 android 允许程序使用socket(XML配置)79 android 允许程序读取日历(XML配置)80 android 允许程序读取系统日志(XML配置)81 android 允许程序读取所有者数据(XML配置)82 android 允许程序读取短信(XML配置)83 android 允许程序重启设备(XML配置)84 android 允许程序录制音频(XML配置)85 android 允许程序发送短信(XML配置)86 android 允许程序将自己置为最前(XML配置)87 android 创建图像图片BitmapResources res = getResources();Bitmap bitmap = BitmapFactory.decodeResource(res, R.drawable.hh);88 android 取得远程图片HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();conn.connect();InputStream is = conn.getInputStream();bitmap = BitmapFactory.decodeStream(is);is.close();89 android 允许程序发送短信(XML配置)90 android 启动和结束服务startService(new Intent(qsr.test.MyService);stopService(new Intent(qsr.test.MyService);91 android 创建和配置Servicepublic class MyService extends Service public IBinder onBind(Intent arg0) return null;public void onStart(Intent intent,int startId)super.onStart(intent, startId);/to do something when startpublic void onDestroy()super.onDestroy();/to do something when stop/xml配置92 android 获得系统感应设备SensorManager sensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE); 93 android 设置控件布局参数textView01.setLayoutParams(new AbsoluteLayout.LayoutParams(100,60,0,0);/高100,宽60,x=0,y=0;);94 android 创建Drawable对象Resources res = getResources();Drawable drawable = res.getDrawable(R.drawable.hh);95 android 访问网页Uri uri = Uri.parse();Intent intent = new Intent(Intent.ACTION_VIEW,uri);startActivity(intent);96 android 打电话Uri uri = Uri.parse(tel:00000000);Intent intent = new Intent(Intent.ACTION_DIAL, uri); startActivity(intent); 97 android 播放歌曲Intent intent = new Intent(Intent.ACTION_VIEW);Uri uri = Uri.parse(file:/sdcard/test.mp3);intent.setDataAndType(uri, audio/mp3);startActivity(intent);98 android 发送邮件Intent intent=new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, The email text); intent.setType(text/plain); startActivity(Intent.createChooser(intent, Choose Email Client);99 android 发短信Uri uri = Uri.parse(smsto:123456789); Intent intent = new Intent(Intent.ACTION_SENDTO, uri); intent.putExtra(sms_body, The SMS text); startActivity(intent);100 android 安装程序Uri installUri = Uri.fromParts(package, xxx, null);Intent intent = new Intent(Intent.ACTION_PACKAGE_ADDED, installUri); startActivity(intent);101 android 卸载程序Uri uninstallUri = Uri.fromParts(package, xxx, null);Intent intent = new Intent(Intent.ACTION_DELETE, uninstallUri); startActivity(intent);102 android 从xml配置获得控件对象/TestActivity.javatextView = (TextView) findViewById(R.id.TextView01);/main.xml103 android 获得触摸屏压力public boolean onTouch(View v, MotionEvent event) float pressure = event.getPressure();return false;104 android 给文本加上滚动条TextView textView = new TextView(this);textView.setText(string);ScrollView scrollView = new ScrollView(this);scrollView.addView(textView);setContentView(scrollView);105 android 获得正在运行的所有服务public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);StringBuffer serviceInfo = new StringBuffer();ActivityManager activityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);List services = activityManager.getRunningServices(256);Iterator iterator = services.iterator();while (iterator.hasNext() RunningServiceInfo si = (RunningServiceInfo)iterator.next();serviceInfo.append(pid: ).append(si.pid);serviceInfo.append(process: ).append(cess);TextView textView = new TextView(this);textView.setText(serviceInfo.toString();ScrollView scrollView = new ScrollView(this);scrollView.addView(textView);setContentView(scrollView);106 android 使用ContentResolver获得联系人姓名和号码ContentResolver cr = getContentResolver();Cursor cur = cr.query(People.CONTENT_URI, null, null, null, null);cur.moveToFirst();do int nameColumn = cur.getColumnIndex(People.NAME);int phoneColumn = cur.getColumnIndex(People.NUMBER);String name = cur.getString(nameColumn);String phoneNumber = cur.getString(phoneColumn);Toast.makeText(this,name,Toast.LENGTH_LONG).show();Toast.makeText(this,phoneNumber,Toast.LENGTH_LONG).show(); while (cur.moveToNext();107 android 创建WebViewWebView webView = new WebView(this);webView.loadData(+test+test+, text/html, utf-8);108 android 设置地图是否显示卫星和街道mapView.setSatellite(false); mapView.setStreetView(true);109 android 单选框清除radioGroup.clearCheck();110 android 给文本增加链接Linkify.addLinks(mTextView01,Linkify.WEB_URLS);Linkify.addLinks(mTextView02,Linkify.EMAIL_ADDRESSES);Linkify.addLinks(mTextView03,Linkify.PHONE_NUMBERS);111 android 设置手机震动Vibrator vibrator = (Vibrator)getApplication().getSystemService(Service.VIBRATOR_SERVICE);vibrator.vibrate( new long1000,1000,1000,1000,-1);/震动一秒,停一秒,再震一秒112 android 创建下拉框Spinner spinner = new Spinner(this);113 android 给spinner添加事件spinner.setOnItemSelectedListener(new
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 能在电脑上写数学试卷
- 蒲城县高二联考数学试卷
- 班级活动方案策划300字(3篇)
- 水渠围堰施工方案(3篇)
- 河北企业线下活动策划方案(3篇)
- 线上签约活动方案策划(3篇)
- 辽宁水帘施工方案(3篇)
- 杭州混凝土施工方案公司(3篇)
- 银行年度活动策划方案(3篇)
- 农村庭院大门施工方案(3篇)
- 征兵心理适应能力测试题及答案
- 2025-2030年中国雾化铜粉行业市场现状供需分析及投资评估规划分析研究报告
- 2024年山西省中考历史真题
- 2025至2030年中国警用执法记录仪行业市场供需规模及竞争战略分析报告
- 2025年第十届“学宪法、讲宪法”网络知识竞赛题库(含答案)
- 公司车辆道闸管理制度
- T/ZHCA 007-2019染发化妆品眼刺激性试验体外测试方法牛角膜浑浊和渗透性试验
- 电梯砝码租凭合同协议书
- (高清版)DG∕TJ 08-2093-2019 电动汽车充电基础设施建设技术标准 含2021年局部修订
- 三年级数学下册计算题专项练习大全(每日一练共22份)
- 炒股保底协议书
评论
0/150
提交评论