当前位置:  编程技术>移动开发
本页文章导读:
    ▪NotificationManager鍜孨otification鐨勪娇鐢ㄦ€荤粨(杞        NotificationManager鍜孨otification鐨勪娇鐢ㄦ€荤粨(杞? 杩欏嚑澶╀竴鐩村湪淇敼twigee鐨勬簮浠g爜锛屽叾涓竴涓鍔犲叆鐨勫姛鑳芥槸甯搁┗Notification鏍忥紝浠ュ墠鍐欑殑鏃跺€欏彧鑳藉.........
    ▪ UITalbeView系列-滑动展示“删除”        UITalbeView系列-滑动显示“删除” 腾讯的QQ和微信中都有这样的操作,对一个UITableView中的cell,向左滑动的时候,会在对应的cell右侧(iOS7.0样式发生了一点变化)出现一个“删除”按钮要达到这.........
    ▪ 仿爱奇艺界面(4)       仿爱奇艺界面(四) 搜索Activity的java内容虽然不多,只是找到两个gridView然后分别给他们设置适配器,但是布局文件里面包含的信息还是很丰富的。 SearchActivity:   public class SearchActivity exten.........

[1]NotificationManager鍜孨otification鐨勪娇鐢ㄦ€荤粨(杞
    来源: 互联网  发布时间: 2014-02-18
NotificationManager鍜孨otification鐨勪娇鐢ㄦ€荤粨(杞?

杩欏嚑澶╀竴鐩村湪淇敼twigee鐨勬簮浠g爜锛屽叾涓竴涓鍔犲叆鐨勫姛鑳芥槸甯搁┗Notification鏍忥紝浠ュ墠鍐欑殑鏃跺€欏彧鑳藉嚭鐜?鍦ㄢ€滈€氱煡鈥濊繖涓€缁勪腑锛屾兂鎶婂畠鏀惧湪鈥滄鍦ㄨ繍琛屸€濈粍涓嵈涓嶇煡閬撴€庝箞鏀撅紝鏌ヤ簡涓嬪畼鏂规枃妗o紝鎵惧埌浜嗘柟娉曪紝鍦╪otification鐨刦lags瀛楁涓姞涓€涓?鈥淔LAG_ONGOING_EVENT鈥濆氨鍙互浜嗐€傚悓鏃舵垜涔熸妸Notification鐨勪娇鐢ㄦ柟娉曠粰鎬荤粨浜嗕竴涓嬨€傝瑙佷笅鏂囷細

(1)銆佷娇鐢ㄧ郴缁熷畾涔夌殑Notification

浠ヤ笅鏄娇鐢ㄧず渚嬩唬鐮侊細

//鍒涘缓涓€涓狽otificationManager鐨勫紩鐢?/p>

String ns = Context.NOTIFICATION_SERVICE;

NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);

//瀹氫箟Notification鐨勫悇绉嶅睘鎬?/p>

int icon = R.drawable.icon; //閫氱煡鍥炬爣

CharSequence tickerText = "Hello"; //鐘舵€佹爮鏄剧ず鐨勯€氱煡鏂囨湰鎻愮ず

long when = System.currentTimeMillis(); //閫氱煡浜х敓鐨勬椂闂达紝浼氬湪閫氱煡淇℃伅閲屾樉绀?/p>

//鐢ㄤ笂闈㈢殑灞炴€у垵濮嬪寲Nofification

Notification notification = new Notification(icon,tickerText,when);

/*

* 娣诲姞澹伴煶

* notification.defaults |=Notification.DEFAULT_SOUND;

* 鎴栬€呬娇鐢ㄤ互涓嬪嚑绉嶆柟寮?/p>

* notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");

* notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");

* 濡傛灉鎯宠璁╁0闊虫寔缁噸澶嶇洿鍒扮敤鎴峰閫氱煡鍋氬嚭鍙嶅簲锛屽垯鍙互鍦╪otification鐨刦lags瀛楁澧炲姞"FLAG_INSISTENT"

* 濡傛灉notification鐨刣efaults瀛楁鍖呮嫭浜?DEFAULT_SOUND"灞炴€э紝鍒欒繖涓睘鎬у皢瑕嗙洊sound瀛楁涓畾涔夌殑澹伴煶

*/

/*

* 娣诲姞鎸姩

* notification.defaults |= Notification.DEFAULT_VIBRATE;

* 鎴栬€呭彲浠ュ畾涔夎嚜宸辩殑鎸姩妯″紡锛?/p>

* long[] vibrate = {0,100,200,300}; //0姣鍚庡紑濮嬫尟鍔紝鎸姩100姣鍚庡仠姝紝鍐嶈繃200姣鍚庡啀娆℃尟鍔?00姣

* notification.vibrate = vibrate;

* long鏁扮粍鍙互瀹氫箟鎴愭兂瑕佺殑浠讳綍闀垮害

* 濡傛灉notification鐨刣efaults瀛楁鍖呮嫭浜?DEFAULT_VIBRATE",鍒欒繖涓睘鎬у皢瑕嗙洊vibrate瀛楁涓畾涔夌殑鎸姩

*/

/*

* 娣诲姞LED鐏彁閱?/p>

* notification.defaults |= Notification.DEFAULT_LIGHTS;

* 鎴栬€呭彲浠ヨ嚜宸辩殑LED鎻愰啋妯″紡:

* notification.ledARGB = 0xff00ff00;

* notification.ledOnMS = 300; //浜殑鏃堕棿

* notification.ledOffMS = 1000; //鐏殑鏃堕棿

* notification.flags |= Notification.FLAG_SHOW_LIGHTS;

*/

/*

* 鏇村鐨勭壒寰佸睘鎬?/p>

* notification.flags |= FLAG_AUTO_CANCEL; //鍦ㄩ€氱煡鏍忎笂鐐瑰嚮姝ら€氱煡鍚庤嚜鍔ㄦ竻闄ゆ閫氱煡

* notification.flags |= FLAG_INSISTENT; //閲嶅鍙戝嚭澹伴煶锛岀洿鍒扮敤鎴峰搷搴旀閫氱煡

* notification.flags |= FLAG_ONGOING_EVENT; //灏嗘閫氱煡鏀惧埌閫氱煡鏍忕殑"Ongoing"鍗?姝e湪杩愯"缁勪腑

* notification.flags |= FLAG_NO_CLEAR; //琛ㄦ槑鍦ㄧ偣鍑讳簡閫氱煡鏍忎腑鐨?娓呴櫎閫氱煡"鍚庯紝姝ら€氱煡涓嶆竻闄わ紝

* //缁忓父涓嶧LAG_ONGOING_EVENT涓€璧蜂娇鐢?/p>

* notification.number = 1; //number瀛楁琛ㄧず姝ら€氱煡浠h〃鐨勫綋鍓嶄簨浠舵暟閲忥紝瀹冨皢瑕嗙洊鍦ㄧ姸鎬佹爮鍥炬爣鐨勯《閮?/p>

* //濡傛灉瑕佷娇鐢ㄦ瀛楁锛屽繀椤讳粠1寮€濮?/p>

* notification.iconLevel = ; //

*/

//璁剧疆閫氱煡鐨勪簨浠舵秷鎭?/p>

Context context = getApplicationContext(); //涓婁笅鏂?/p>

CharSequence contentTitle = "My Notification"; //閫氱煡鏍忔爣棰?/p>

CharSequence contentText = "Hello World!"; //閫氱煡鏍忓唴瀹?/p>

Intent notificationIntent = new Intent(this,Main.class); //鐐瑰嚮璇ラ€氱煡鍚庤璺宠浆鐨凙ctivity

PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);

notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

//鎶奛otification浼犻€掔粰NotificationManager

mNotificationManager.notify(0,notification);

濡傛灉鎯宠鏇存柊涓€涓€氱煡锛屽彧闇€瑕佸湪璁剧疆濂絥otification涔嬪悗锛屽啀娆¤皟鐢?setLatestEventInfo(),鐒跺悗閲嶆柊鍙戦€佷竴娆¢€氱煡鍗冲彲锛屽嵆鍐嶆璋冪敤notify()銆?/p>

(2)銆佷娇鐢ㄨ嚜瀹氫箟鐨凬otification

瑕?鍒涘缓涓€涓嚜瀹氫箟鐨凬otification锛屽彲浠ヤ娇鐢≧emoteViews銆傝瀹氫箟鑷繁鐨勬墿灞曟秷鎭紝棣栧厛瑕佸垵濮嬪寲涓€涓猂emoteViews瀵硅薄锛岀劧鍚?灏嗗畠浼犻€掔粰Notification鐨刢ontentView瀛楁锛屽啀鎶奝endingIntent浼犻€掔粰contentIntent瀛楁銆備互涓嬬ず渚嬩唬鐮?鏄畬鏁存楠わ細

//1銆佸垱寤轰竴涓嚜瀹氫箟鐨勬秷鎭竷灞€ view.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="fill_parent" android:layout_height="fill_parent">

<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>

//2銆佸湪绋嬪簭浠g爜涓娇鐢≧emoteViews鐨勬柟娉曟潵瀹氫箟image鍜宼ext銆傜劧鍚庢妸RemoteViews瀵硅薄浼犲埌contentView瀛楁

RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.view);

contentView.setImageViewResource(R.id.image,R.drawable.icon);

contentView.setTextViewText(R.id.text,鈥滺ello,this message is in a custom expanded view鈥?;

notification.contentView = contentView;

//3銆佷负Notification鐨刢ontentIntent瀛楁瀹氫箟涓€涓狪ntent(娉ㄦ剰锛屼娇鐢ㄨ嚜瀹氫箟View涓嶉渶瑕乻etLatestEventInfo()鏂规硶)

Intent notificationIntent = new Intent(this,Main.class);

PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);

notification.contentIntent = contentIntent;

//4銆佸彂閫侀€氱煡

mNotificationManager.notify(2,notification);

//浠ヤ笅鏄叏閮ㄧず渚嬩唬鐮?/strong>

//鍒涘缓涓€涓狽otificationManager鐨勫紩鐢?/p>

String ns = Context.NOTIFICATION_SERVICE;

NotificationManager mNotificationManager = (NotificationManager)getSystemService(ns);

//瀹氫箟Notification鐨勫悇绉嶅睘鎬?/p>

int icon = R.drawable.icon; //閫氱煡鍥炬爣

CharSequence tickerText = "Hello"; //鐘舵€佹爮鏄剧ず鐨勯€氱煡鏂囨湰鎻愮ず

long when = System.currentTimeMillis(); //閫氱煡浜х敓鐨勬椂闂达紝浼氬湪閫氱煡淇℃伅閲屾樉绀?/p>

//鐢ㄤ笂闈㈢殑灞炴€у垵濮嬪寲Nofification

Notification notification = new Notification(icon,tickerText,when);

RemoteViews contentView = new RemoteViews(getPackageName(),R.layout.view);

contentView.setImageViewResource(R.id.image, R.drawable.iconempty);

contentView.setTextViewText(R.id.text, "Hello,this is JC");

notification.contentView = contentView;

Intent notificationIntent = new Intent(this,Main.class);

PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);

notification.contentIntent = contentIntent;

//鎶奛otification浼犻€掔粰NotificationManager

mNotificationManager.notify(0,notification);


    
[2] UITalbeView系列-滑动展示“删除”
    来源: 互联网  发布时间: 2014-02-18
UITalbeView系列-滑动显示“删除”

腾讯的QQ和微信中都有这样的操作,对一个UITableView中的cell,向左滑动的时候,会在对应的cell右侧(iOS7.0样式发生了一点变化)出现一个“删除”按钮

要达到这样的效果,完全用系统的就可以,不需要自定义一个Button,加到cell后面,同时给cell加手势捕获这个操作。

注意:如果在cell加一个手势(测试中我用的Pan),那么cell系统自己的就不生效了。

生效主要依赖3个代理方法(要是说成一个也行)
(1)- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
这是最主要的方法,如果要显示“删除”,把这个“按钮”的响应事件写好。

(2)- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

“Allows customization of the editingStyle for a particular cell located at 'indexPath'. If not implemented, all editable cells will have UITableViewCellEditingStyleDelete set for them when the table has editing property set to YES.”

就像API中说的一样,“如果不实现,所有的cell(默认都是可编辑的)都会有UITableViewCellEditingStyleDelete这个类型”,所以不写这个方法,照样能出现。但是,如果你对indexPath的cell返回了其他Style,那就没有了。
所以,根据具体逻辑和业务,灵活返回具体的Style

(3)- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath


“Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable.”
在(2)中已经提到了,所有的cell都是默认可编辑的


总结:如果要单纯的实现“滑动出现删除按钮”,只需要实现(1)就OK了。
通过(2)(3)的配合,完成相应的逻辑和业务。
至于调用顺序:
(3)是在UITableViewDataSource中的,table显示的时候就调用了,处在第一响应位。
(2)如果某一行可以编辑,会调用这个返回具体的Style。
(1)则是点击了“按钮”以后才会进的。

附:
如果要更改按钮的title,很简单实现另外一个代理方法。
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

    
[3] 仿爱奇艺界面(4)
    来源: 互联网  发布时间: 2014-02-18
仿爱奇艺界面(四)

搜索Activity的java内容虽然不多,只是找到两个gridView然后分别给他们设置适配器,但是布局文件里面包含的信息还是很丰富的。

SearchActivity:

 

public class SearchActivity extends Activity {
	GridView mHotGridView, mHistoryGridView;	//热门搜索和搜索历史

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.search_activity);
		prepareView();
	}

	private void prepareView() {
		mHotGridView = (GridView) findViewById(R.id.hot_search_grid);
		mHotGridView.setAdapter(new GridAdapter(this));
		mHistoryGridView = (GridView) findViewById(R.id.history_search_grid);
		mHistoryGridView.setAdapter(new GridAdapter(this));
	}
}

 接下来是适配器GridAdapter的代码,学习了gridView的话应该是轻车熟路了,把test1里面的倒霉熊什么的都写上去:

public class GridAdapter extends BaseAdapter {
	Context mContext;
	String[] test1 = new String[] { "开心魔法", "奋斗", "导火索", "碟中谍4", "碟中碟3",
			"美人心计", "倒霉熊", "火影忍者", "喜洋洋", "北京爱情故事" };

	public GridAdapter(Context cnt) {
		this.mContext = cnt;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return test1.length;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		if (arg1 == null) {
			arg1 = LayoutInflater.from(mContext).inflate(
					R.layout.search_grid_item, null);
		}
		TextView tv = (TextView) arg1.findViewById(R.id.title);
		tv.setText(test1[arg0]);
		return arg1;
	}

}

 布局文件里面用到的东西很多了,我把重点的讲下transparent这是图片重叠透明穿透,就是两张png的图片合在一块,不是覆盖。这里的效果就是摁下字,背景变了。

search_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/phonetitlebar_bg"
        android:gravity="center" >

        <EditText
            android:id="@+id/editText1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/edittext_search"
            android:drawableLeft="@drawable/edittext_search_image"
            android:hint="@string/search_hit"
            android:paddingLeft="15dip"
            android:textSize="14dip" >
        </EditText>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/button_search_background"
            android:text="@string/search_text" />
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/search_main_tree_bg"
        android:gravity="center_vertical"
        android:paddingLeft="15dip"
        android:text="@string/hot_search"
        android:textColor="#000000"
        android:textSize="18dip" />

    <GridView
        android:id="@+id/hot_search_grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dip"
        android:layout_marginRight="30dip"
        android:layout_marginTop="15dip"
        android:layout_weight="1"
        android:horizontalSpacing="50dip"
        android:numColumns="2"
        android:listSelector="@drawable/list_seletor_transparent" android:scrollbars="none">
    </GridView>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/search_main_tree_bg"
        android:gravity="center_vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:paddingLeft="15dip"
            android:text="@string/search_history"
            android:textColor="#000000"
            android:textSize="18dip" />

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dip"
            android:background="@drawable/clear_but_background"
            android:text="@string/clear_search_history"
            android:textColor="#ffffff" />
    </LinearLayout>

    <GridView
        android:id="@+id/history_search_grid"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dip"
        android:layout_marginRight="30dip"
        android:layout_marginTop="15dip"
        android:layout_weight="1"
        android:horizontalSpacing="50dip"
        android:numColumns="2"
        android:listSelector="@drawable/list_seletor_transparent" android:scrollbars="none">
    </GridView>

</LinearLayout>

 

search_grid_item.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/hot_search_background" 
    android:paddingLeft="3dip"
    android:paddingBottom="3dip" 
    android:paddingTop="3dip">

    <TextView
        android:id="@+id/title"
        android:layout_width="80dip"
        android:layout_height="wrap_content" android:singleLine="true"/>

</LinearLayout>

 

PS:上面有些东西就没全部贴出来了,待会把整个源码贴上去,自己找了。


    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android实现将已发送的短信写入短信数据库的... iis7站长之家
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3