Android相关的代码片段

1.测试Notification

private void showNotification() {
        NotificationManager manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);

        Intent intent=new Intent(MainActivity.this,ArrayAdapterActivity.class);
        PendingIntent pendingIntent=PendingIntent.getActivity(MainActivity.this,0,intent,PendingIntent.FLAG_ONE_SHOT);

        Notification notification=new Notification.Builder(this)
                .setAutoCancel(true)
                .setContentTitle("通知")
                .setContentIntent(pendingIntent)
                .setSmallIcon(R.mipmap.t)
                .setWhen(System.currentTimeMillis())
                .setDefaults(Notification.DEFAULT_ALL).build();
        manager.notify(10,notification);
  }
  // NotificationManager manager=(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
  // manager.cancel(10);

2.读取xml文档

 private void getXML() {
        XmlResourceParser xmlResourceParser=getResources().getXml(R.xml.customers);
        StringBuffer stringBuffer=new StringBuffer();
        try {
            while (xmlResourceParser.getEventType()!=XmlResourceParser.END_DOCUMENT){
                if (xmlResourceParser.getEventType()==XmlResourceParser.START_TAG){
                    String tagName=xmlResourceParser.getName();
                    if (tagName.equals("customer")){
                        stringBuffer.append("姓名:" + xmlResourceParser.getAttributeValue(0) + "   ");		//获取客户姓名
                        stringBuffer.append("联系电话:" + xmlResourceParser.getAttributeValue(1) + "   ");	//获取联系电话
                        stringBuffer.append("E-mail:" + xmlResourceParser.getAttributeValue(2));	//获取E-mail
                        stringBuffer.append("\n");	//添加换行符
                    }
                }
                xmlResourceParser.next();

            }
        }catch (Exception e){
            e.printStackTrace();
        }
        textView.setText(stringBuffer);
    }
customers.xml

<?xml version="1.0" encoding="utf-8"?>
<customers>
	<customer name="wgh" tel="1363*******" email="wgh8007@163.com"/>
    <customer name="mr" tel="0431-84******" email="mingrisoft@mingirsoft.com"/>
    <customer name="sk" tel="130********" email="sk666888@sina.com" />
</customers>
3.设置FrameLayout,显示渐变视图

public class MyView extends View{

        public MyView(Context context) {
            super(context);
        }

        @Override
        protected void onDraw(Canvas canvas) {
            Paint paint=new Paint();
            //线性渐变
            Shader shader=new LinearGradient(0,0,50,50, Color.RED,Color.GREEN,Shader.TileMode.MIRROR);
            paint.setShader(shader);
            canvas.drawRect(10 ,70,100,150,paint);

            //径向渐变
            shader=new RadialGradient(160,110,50,Color.RED,Color.GREEN,Shader.TileMode.MIRROR);
            paint.setShader(shader);
            canvas.drawRect(115,70,205,150,paint);

            //角度渐变
            shader=new SweepGradient(265,110,new int[]{Color.RED,Color.GREEN,Color.BLUE},null);
            paint.setShader(shader);
            canvas.drawRect(220,70,310,150,paint);
            super.onDraw(canvas);
        }
    }
</pre><pre code_snippet_id="1621313" snippet_file_name="blog_20160323_7_8349943" name="code" class="java">//frameLayout.addView(new MyView(this));
4.自定义菜单

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
    <item android:id="@+id/item1"
        android:title="更换背景"
        android:alphabeticShortcut="g"
        android:orderInCategory="100" app:showAsAction="never" />
    <item android:id="@+id/item2"
        android:title="编辑组件"
        android:alphabeticShortcut="t"
        android:orderInCategory="100" app:showAsAction="never" />

    <item android:id="@+id/item3" android:title="恢复默认">
        <menu>
            <group android:id="@+id/setting">
                <item android:id="@+id/sound" android:title="使用背景"></item>
                <item android:id="@+id/video" android:title="背景音乐"></item>
            </group>
        </menu>
    </item>
</menu>
5.webview的使用
   webView=(WebView)findViewById(R.id.webView);
        WebSettings webSettings=webView.getSettings();
        //设置支持JavaScript
        webSettings.setJavaScriptEnabled(true);
        //在WebView中打开所有链接
        webView.setWebViewClient(new WebViewClient());
        Intent intent=getIntent();
       String url=intent.getStringExtra("web_url");
        webView.loadUrl(url);







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值