zoukankan      html  css  js  c++  java
  • Android为TV端助力 自定义通知栏

    package com.example.mvp;

    import cn.ljuns.temperature.view.TemperatureView;
    import presenter.ILoginPresenter;
    import presenter.LoginPresenterCompl;
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.app.PendingIntent;
    import android.graphics.BitmapFactory;
    import android.graphics.Color;
    import android.graphics.drawable.BitmapDrawable;
    import android.util.Log;
    import android.view.Gravity;
    import android.view.LayoutInflater;
    import android.view.Menu;
    import android.view.VelocityTracker;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.Window;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.PopupWindow;
    import android.widget.RemoteViews;
    import android.widget.Toast;
    import android.app.ActionBar.LayoutParams;
    import android.content.Context;
    import android.content.Intent;
    public class MainActivity extends Activity implements ILoginView{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_main);
    Notification notification = new Notification();
    //设置图标,后面的自定义布局的图片会覆盖它,但还是得设置,不然不会显示到通知栏
    notification.icon = R.drawable.ic_launcher;
    notification.tickerText = "hello I am gougou";
    notification.when = System.currentTimeMillis();
    notification.flags = Notification.FLAG_AUTO_CANCEL;
    //传入当前项目的包名,和你通知栏上要显示的自定义布局的ID
    RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.activity_amain);
    //下面都是设置通知栏布局里面控件的属性
    remoteViews.setImageViewResource(R.id.imageView1, R.drawable.hot);
    remoteViews.setTextColor(R.id.textView1, Color.RED);
    remoteViews.setTextViewText(R.id.textView1, "hello I am 小篮子");
    remoteViews.setTextViewTextSize(R.id.textView1, 1, 15);
    // PendingIntent有4种flag.
    // - FLAG_ONE_SHOT 只执行一次
    // - FLAG_NO_CREATE 若描述的Intent不存在则返回NULL值
    // - FLAG_CANCEL_CURRENT 如果描述的PendingIntent已经存在,则在产生新的Intent之前会先取消掉当前的
    // - FLAG_UPDATE_CURRENT 总是执行,这个flag用的最多
    PendingIntent pendingIntent = PendingIntent.getActivity(
    this, 0, new Intent(this,AMainActivity.class),
    PendingIntent.FLAG_UPDATE_CURRENT);
    remoteViews.setOnClickPendingIntent(R.id.textView1, pendingIntent);
    notification.contentView = remoteViews;
    notification.contentIntent = pendingIntent;

    NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(1, notification);
    }

     R.layout.activity_amain 的布局

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".AMainActivity" >


    <ImageView
    android:id="@+id/imageView1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    />
    <TextView
    android:id="@+id/textView1"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    android:clickable="true"
    />


    <TextView
    android:id="@+id/textView2"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:layout_height="wrap_content"
    />
    </LinearLayout>

  • 相关阅读:
    sitemap怎么制作才适合蜘蛛抓取?
    网站高并发优化性能调优总结
    圆柱模板行业B2B站点打造MIP推送+熊掌号推送+历史普通推送插件
    a href="javascript:void(0)" 是什么意思?加不加上有什么区别?
    <a href="#" onclick="history.back();"></a>这样写为什么是对的? -(转)
    form 表单 enctype 属性-(转自w3c)
    关于submit与document.form1.submit();这2个提交的区别
    zf-表单填写以及相关业务流程
    zf-关于把某个地址的svn项目移动到另一个上面的步骤
    zf-关于即将过期提示字符串的修改
  • 原文地址:https://www.cnblogs.com/xiaoxiaing/p/5849756.html
Copyright © 2011-2022 走看看