activity_activitywenben.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <AutoCompleteTextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/atv_1" android:hint="自动完成文本编辑框"/> <Spinner android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/sper_1"> </Spinner> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="显示状态栏提示" android:onClick="notification_onclick"/> </LinearLayout>
java
package com.example.chenshuai.test321; import android.app.Notification; import android.app.NotificationManager; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Spinner; import android.widget.Toast; public class Activitywenben extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_activitywenben); //自动提示文本框 AutoCompleteTextView autv_1 = (AutoCompleteTextView)findViewById(R.id.atv_1); //设置数据源 String[] str = {"a","aa","aaa","ab","abc","abcd"}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.listview_layout,str); autv_1.setAdapter(adapter); //下拉列表 Spinner sper_1 = (Spinner)findViewById(R.id.sper_1); sper_1.setAdapter(adapter); sper_1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(Activitywenben.this, "position" +position, Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(Activitywenben.this, "什么也不选", Toast.LENGTH_SHORT).show(); } }); } public void notification_onclick(View view){ //1.获取状态栏消息管理器 NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); // Notification nt = new Notification.Builder(this) .setContentTitle("这是一条消息通知") .setContentText("hello world 通知:明天休息") .setTicker("显示在状态栏中的信息") .setSmallIcon(R.drawable.anniu1) .setAutoCancel(true) .setDefaults(Notification.DEFAULT_SOUND) .build(); //交给管理器发出消息 manager.notify(0,nt); } }