day12、13-design、极光推送

design

Material design和Support library控件

主要包括TextInputLayout、SwitchCompat、SnackBar、FloatingActionButton、Shadows、Ripples、TabLayout、RecyclerView、Card、NavigationView、BottomSheet、Palette控件。

使用:

Android Material Design 添加依赖
https://blog.youkuaiyun.com/yjdsqb/article/details/80140593
//添加依赖
implementation ‘com.android.support:design:28.0.0’

细节

通过android:src修改图片
通过app:backgroundTint修改背景颜色
通过app:fabSize设置大小,只有两个选项normal和mini
xmlns:app=“http://schemas.android.com/apk/res-auto
12.

<android.support.design.widget.NavigationView
    android:id="@+id/navId"
    android:layout_width="300dp"
    android:layout_height="match_parent"
    android:layout_gravity="right"
    app:headerLayout="@layout/header_view_layout"
    app:menu="@menu/menu">
</android.support.design.widget.NavigationView>

Menu 布局

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:id="@+id/action_set"
        android:title="设置"
        android:icon="@mipmap/settings"/>

    <item android:id="@+id/action_about"
        android:title="关于"
        android:icon="@mipmap/message_icon"/>

    <item android:id="@+id/action_clear"
        android:title="清除"
        android:icon="@android:drawable/ic_notification_clear_all"/>
    <item android:id="@+id/action_btn"		
        android:title="测试"
        android:icon="@mipmap/ic_launcher"/>
</menu>
//获取NavigationView
nv = findViewById(R.id.navId);
drawerLayout = findViewById(R.id.rootId);
//获取navigation head view;
View headerView = nv.getHeaderView(0);
//获取headview的imagview
littleImg = headerView.findViewById(R.id.littleBoyImg);

极光推送

步骤

1,注册,登录成为开发者。 官方网站:https://www.jiguang.cn
2,在控制台创建应用: 参考链接:https://www.jiguang.cn/dev/#/app/list#dev
3,设置包名。包名一定和应用程序包名一致。
在这里插入图片描述
4,生成对应的AppKey
在这里插入图片描述
5,集成sdk 使用jcenter自动集成
https://docs.jiguang.cn//jpush/client/Android/android_guide/#jcenter
在这里插入图片描述
6,定义一个Application类,在oncreate里调用。

JPushInterface.setDebugMode(true);//调试模式。
JPushInterface.init(this);

7,在AndroidManifest.xml里, 添加 Application。
8,定义一个receiver例如MyReceiver, 继承 BroadcastReceiver,并重写onReceiver函数。

9,在AndroidManifest中注册MyReceiver。注意包名别忘了写。

<receiver
    android:name=".MyReceiver"
    android:enabled="true"
    android:exported="false">
    <intent-filter>
        <action android:name="cn.jpush.android.intent.REGISTRATION" />
        <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
        <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
        <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
        <action android:name="cn.jpush.android.intent.NOTIFICATION_CLICK_ACTION" />
        <action android:name="cn.jpush.android.intent.CONNECTION" />
        <category android:name="com.bawei.jiguang1610" />
    </intent-filter>
</receiver>

10,在MyReceiver里接收信息。
参考链接:https://docs.jiguang.cn//jpush/client/Android/android_api/#receiver

public class MyReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction() ==     
JPushInterface.ACTION_MESSAGE_RECEIVED) {

            Bundle bundle = intent.getExtras();
            String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);//读取自定义信息内容
            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); //读取自定义信息附加字段, 是一个json字符串。
            String value = null;
            try {
                JSONObject jsonObject = new JSONObject(extras);
                value = (String) jsonObject.get("class"); //读取附件字段class的value值.
            } catch (JSONException e) {
                e.printStackTrace();
            }
            Log.d("onReceive:", "ACTION_MESSAGE_RECEIVED::" + message);

        } else if (intent.getAction() == JPushInterface.ACTION_NOTIFICATION_RECEIVED) {
            Log.d("onReceive:", "ACTION_NOTIFICATION_RECEIVED");
            Bundle bundle = intent.getExtras();
            String content = bundle.getString(JPushInterface.EXTRA_ALERT); //读取通知内容
            Log.d("onReceive:", "ACTION_MESSAGE_RECEIVED::" + content);
            String extras = bundle.getString(JPushInterface.EXTRA_EXTRA); //读取自定义信息附加字段, 是一个json字符串。
            String value = null;
            try {
                JSONObject jsonObject = new JSONObject(extras);
                value = (String) jsonObject.get("class"); //读取附件字段class的value值.
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }
}

11,控制台发送自定义信息:
在这里插入图片描述
12,控制台发送通知:
在这里插入图片描述

https://mob.com/ 第三方分享

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值