资源描述:
《android编程14个很有用的代码片段》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、Android编程14个很有用的代码片段1、查看是否有存储卡插入[java]viewplaincopyprint?1.Stringstatus=Environment.getExternalStorageState();2.3.if(status.equals(Enviroment.MEDIA_MOUNTED))4.{5.说明有SD卡插入6.}Stringstatus=Environment.getExternalStorageState();if(status.equals(Enviroment.MEDIA_MOUNTED)){说明有SD卡插入}2、
2、让某个Activity透明[java]viewplaincopyprint?1.OnCreate中不设Layout2.3.this.setTheme(R.style.Theme_Transparent);4.5.以下是Theme_Transparent的定义(注意transparent_bg是一副透明的图片)OnCreate中不设Layoutthis.setTheme(R.style.Theme_Transparent);以下是Theme_Transparent的定义(注意transparent_bg是一副透明的图片)3、在屏幕元素中设置句柄使用Act
3、ivity.findViewById来取得屏幕上的元素的句柄.使用该句柄您可以设置或获取任何该对象外露的值.[java]viewplaincopyprint?1.TextViewmsgTextView=(TextView)findViewById(R.id.msg);2.3.msgTextView.setText(R.string.push_me);TextViewmsgTextView=(TextView)findViewById(R.id.msg);msgTextView.setText(R.string.push_me);4、发送短信[java]
4、viewplaincopyprint?1.Stringbody=”thisismmsdemo”;2.1.Intentmmsintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(”smsto”,number,null));2.3.mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);4.mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);5.mmsi
5、ntent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);6.7.startActivity(mmsintent);Stringbody=”thisismmsdemo”;Intentmmsintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(”smsto”,number,null));mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);mmsintent.pu
6、tExtra(Messaging.KEY_ACTION_SENDTO_COMPOSE_MODE,true);mmsintent.putExtra(Messaging.KEY_ACTION_SENDTO_EXIT_ON_SENT,true);startActivity(mmsintent);5、发送彩信[java]viewplaincopyprint?1.StringBuildersb=newStringBuilder();2.3.sb.append(”file://”);4.5.sb.append(fd.getAbsoluteFile());6.7.I
7、ntentintent=newIntent(Intent.ACTION_SENDTO,Uri.fromParts(”mmsto”,number,null));8.9.//Belowextradatasarealloptional.10.intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_SUBJECT,subject);11.intent.putExtra(Messaging.KEY_ACTION_SENDTO_MESSAGE_BODY,body);12.intent.putExtra(Messagi
8、ng.KEY_ACTION_SENDTO_CONTENT_URI,sb.toString())