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);