The examples in this article summarize the classic code snippets for Android programming. Share to everyone for your reference, specific as follows:
1, copy, paste
Clip = (Clipboardmanager) getsystemservice (context.clipboard_service);
Clip.settext ("copy"); Copy
clip.gettext ();//paste
2, call the browser
The core code is as follows:
Intent Intent = new Intent ();
Intent.setaction ("Android.intent.action.VIEW");
Uri Content_url = Uri.parse ("http://www.jb51.net");
Intent.setdata (Content_url);
Invokes the specified browser-uc
intent.setclassname ("Com.uc.browser", "com.uc.browser.ActivityUpdate");
StartActivity (Intent);
Specific steps and implementation code can refer to the previous "Android Development browser usage Examples"
3, according to the package name, to the software market search
Intent Intent = new Intent (Intent.action_view, Uri.parse ("Market://search?q=pname:com.acp.main"));
StartActivity (Intent);
4, Toast has been shown
Final Toast Toast = toast.maketext (Context, "Toast", Toast.length_long);
Timer timer = new timer ();
Timer.schedule (New TimerTask () {
@Override public
void Run () {
//TODO auto-generated methodstub
while (flag) {
toast.show ();}}
, 10);
5, custom Dialog
Final Dialog Minfodlg = new Dialog (context,r.style.dialog);
r.style.dialog– Remove the top title section of the dialog
Layoutinflater Factory = layoutinflater.from (context);
View Ncurrview = factory.inflate (R.layout.mydialog, null);
Ncurrview.setbackgroundresource (r.drawable.bgline);
LinearLayout nparentlayout = (linearlayout) Ncurrview.findviewbyid (r.id.iparents);
Nparentlayout.setbackgroundresource (r.drawable.titlebgline);
Minfodlg.setcontentview (Ncurrview);
Button nBt1 = (button) Ncurrview.findviewbyid (r.id.button1);
Nbt1.settext ("return");
Nbt1.settypeface (Typeface.create (Typeface.serif, Typeface.bold));
Nbt1.setonclicklistener (New Button.onclicklistener () {
@Override public
void OnClick (View v) {
//TODO auto-generated methodstub
Minfodlg.dismiss ();
}
);
Minfodlg.show ();
R.style.dialog:
<?xml version= "1.0" encoding= "Utf-8"?> <resources> <style name= "dialog" parent= "
@android: Style/theme.dialog ">
<itemname=" android:windownotitle ">true</item>
</style>
</resources>
R.drawable.titlebgline:
<?xml version= "1.0" encoding= "Utf-8"?> <shapexmlns:android=
"http://schemas.android.com/apk/res/" Android ">
<gradientandroid:startcolor=" #ff9911 "android:endcolor=" #FF9911 "/>
< Strokeandroid:width= "1DP" android:color= "@color/inputtxt"/>
<cornersandroid:radius= "5DP"/>
</shape>
I hope this article will help you with the Android program.