当前位置: 编程技术>移动开发
本页文章导读:
▪Notificatin 施用 Notificatin 使用
Notificatin [功能]左上角的那个信息提示 可以弹出一些信息 比如 状态更新 或 其他[思路]1. 得到NotificationManager 用于把Notification抛出2. 构造一个Notification 设定与Notification相关.........
▪ 责任书editView大小不变防止输入过多变形以及TextView的style引用 保证editView大小不变防止输入过多变形以及TextView的style引用
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumn.........
▪ 彻底关闭程序历程 彻底关闭程序进程
最近有很多人反应在触发Back按钮后,程序没有完全退出,依然可以通过DDMS看到程序的进程。或者再次启动程序后跳出 “ The application stopped unexpectedly, try again ”。解决以上.........
[1]Notificatin 施用
来源: 互联网 发布时间: 2014-02-18
Notificatin 使用
Notificatin
[功能]
左上角的那个信息提示 可以弹出一些信息 比如 状态更新 或 其他
[思路]
1. 得到NotificationManager 用于把Notification抛出
2. 构造一个Notification 设定与Notification相关的信息 包括2个方面:左上角提示信息 和 Expanded 信息
[实现]
1. 得到NotificationManager的实例 用于抛出Notification
2. 构造一个Notification 并传入一些信息 比如 图标 文字 弹出时间
3. 设定Notification的expand 信息 可通过 HOMR->MENU->Notification 查看
4. 抛出Notification.
5. 定制Expand 信息也是可以的
× 定制目标的 custom_notification_layout.xml
× 设定一些使用信息 比如 文章内容
其他信息稍后补充 比如 Notification弹出的地方 Expand地方!
Notificatin
[功能]
左上角的那个信息提示 可以弹出一些信息 比如 状态更新 或 其他
[思路]
1. 得到NotificationManager 用于把Notification抛出
2. 构造一个Notification 设定与Notification相关的信息 包括2个方面:左上角提示信息 和 Expanded 信息
[实现]
1. 得到NotificationManager的实例 用于抛出Notification
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
2. 构造一个Notification 并传入一些信息 比如 图标 文字 弹出时间
int icon = R.drawable.icon;
CharSequence tickerText = "HelloNotfication";
long when = System.currentTimeMillis();
Notification notification = new Notification(icon, tickerText, when);;
notification.defaults=Notification.DEFAULT_SOUND;
3. 设定Notification的expand 信息 可通过 HOMR->MENU->Notification 查看
//to definition some vale in Expanded view
CharSequence contentTitle = "Notification's title @ Expanded view"; // expanded message title
CharSequence contentText = "Notification's text @ Expanded view"; // expanded message text
//to definition an Intent that this Notification listener in Expanded view via clicked action
Intent notificationIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://110"));
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(this, contentTitle, contentText, contentIntent);
4. 抛出Notification.
manager.notify(1, notification);
5. 定制Expand 信息也是可以的
× 定制目标的 custom_notification_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="3dp"
>
<ImageView android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="10dp"
/>
<TextView android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#000"
/>
</LinearLayout>
× 设定一些使用信息 比如 文章内容
// to customize its Expanded view via XML file RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification_layout); contentView.setImageViewResource(R.id.image, R.drawable.msn); // to specific the text in Expanded view contentView.setTextViewText(R.id.text, "Hello, this is Expanded view with custom XML"); notification.contentView = contentView;
其他信息稍后补充 比如 Notification弹出的地方 Expand地方!
[2] 责任书editView大小不变防止输入过多变形以及TextView的style引用
来源: 互联网 发布时间: 2014-02-18
保证editView大小不变防止输入过多变形以及TextView的style引用
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="1"
android:padding="5dip">
<TableRow>
<TextView
android:id="@+id/label1"
android:text="@string/label1text"
android:layout_column="0"
/>
<EditText
android:id="@+id/edit1"
android:layout_column="1"
/>
</TableRow>
<style name="label" parent="@android:style/Widget.TextView">
<item name="android:gravity">right</item>
<item name="android:paddingRight">5dip</item>
<item name="android:paddingTop">15dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
</style>
<style name="edit" parent="@android:style/Widget.EditText">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">0</item>
<item name="android:layout_weight">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:fadingEdge">vertical</item>
<item name="android:inputType">text</item>
</style>
红色部分就是要设置的。
<TableLayout android:id="@+id/homelayout"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TableRow>
<TextView android:id="@+id/labelartist"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="Find artists:" />
</TableRow>
<TableRow>
<EditText android:id="@+id/entryartist"
android:layout_width="wrap_content" android:layout_height="0"
android:background="@android:drawable/editbox_background"
android:singleLine="true"
android:editable="true"
android:layout_weight="3"
android:padding="5px"
/>
<Button android:id="@+id/okartist" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_marginLeft="10dip"
android:layout_weight="1"
android:text="Search" />
</TableRow>
</TableLayout>
[3] 彻底关闭程序历程
来源: 互联网 发布时间: 2014-02-18
彻底关闭程序进程
最近有很多人反应在触发Back按钮后,程序没有完全退出,依然可以通过DDMS看到程序的进程。或者再次启动程序后跳出 “ The application stopped unexpectedly, try again ”。
解决以上问题的方法:
在onDestroy()方法中加入 Process.killProcess 彻底终止当前程序进程。
源代码 (Java):
1
protected void onDestroy()
2
{
3
super.onDestroy();
4
5
// After this is called, your app process is no longer available in DDMS
6
android.os.Process.killProcess(android.os.Process.myPid());
7
}
1 楼
gaogaf
2010-11-01
单一activity还好,多个就不行了。
最新技术文章: