网友通过本文主要向大家介绍了安卓第三方登录,第三方安卓系统,疯狂安卓讲义第三版,安卓第三方rom,安卓第三方支付等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
安卓第三天笔记--通知-进度条-时期,安卓第三天
安卓第三天笔记--通知-进度条-时期
1.通知Notification
通知就是在是上方的状态栏弹出通知消息
<RelativeLayout 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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <Button android:onClick="send" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送通知" /> </RelativeLayout>
<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/tv" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="这是通知的跳转页面"/> <ImageView android:id="@+id/iv" android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/swift"/> </LinearLayout>
/** * 收到通知时,点击通知打开的Activity * @author 刘楠 * * 2016-2-19下午11:03:44 */ public class OtherActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.other); } } ManiActivity /** * 发送通知 * @author 刘楠 * * 2016-2-19下午7:20:05 */ public class MainActivity extends Activity { private NotificationManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取通知管理器 manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); } /** * 发送通知 * @param v */ @SuppressLint("NewApi") public void send(View v){ //创建一个启动的Intent意图 Intent intent = new Intent(); intent.setClass(this, OtherActivity.class); //打开A description of an Intent and target action to perform with it PendingIntent pendingIntent =PendingIntent.getActivity(this, 0, intent, 0); //建立通知 Notification notification = new Notification.Builder(this) //设置打开通知 .setAutoCancel(true) //状态栏显示的信息 .setTicker("状态栏显示的信息") //设置通知的图标 .setSmallIcon(R.drawable.notify) //设置内容标题 .setContentTitle("一条新的通知") //设置通知的内容 .setContentText("恭喜您,您加薪了,工资增加20%") .setContentIntent(pendingIntent) //设置通知的声音 .build(); //发送一个通知 manager.notify(0, notification); } }
2.TitleProgressBar
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="显示" /> <Button android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="隐藏" /> </LinearLayout>
/** * 标题栏上方显示进度条 * @author 刘楠 * * 2016-2-19下午11:12:21 */ public class MainActivity extends Activity { private Button btn1; private Button btn2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_PROGRESS);