`
haierboos
  • 浏览: 443508 次
文章分类
社区版块
存档分类
最新评论

android之知识点小结一

 
阅读更多

Manifest.xml文件中的一些代码作用:

				<activity android:name=".LunchList"
						  android:label="@string/app_name">
						<intent-filter>
								<action android:name="android.intent.action.MAIN" />
								<category android:name="android.intent.category.LAUNCHER" />
						</intent-filter>
						<intent-filter>
								<action android:name="android.intent.action.SEARCH" />
								<category android:name="android.intent.category.DEFAULT" />
						</intent-filter>
						<meta-data android:name="android.app.searchable"
								   android:resource="@xml/searchable" />
						<meta-data android:name="android.app.default_searchable"
								   android:value=".LunchList" />
				</activity>

在上面这段代码中,

<intent-filter>
        <action android:name="android.intent.action.SEARCH" />
        <category android:name="android.intent.category.DEFAULT" />
      </intent-filter>

这个是注册的隐式Intent的过滤器,第二行表示过滤带有搜索action的intent,第三行是必须要添加的(自定义的Activity如果要通过隐式intent启动,则必须添加)

<meta-data android:name="android.app.searchable"
	  android:resource="@xml/searchable" />

这个是在使用默认的搜索框架是,给搜索框设置的布局,第一行name是给定的,第二行resource就是你给自己的搜索框设置的外观布局,一般放在res/xml里

<meta-data android:name="android.app.default_searchable"
           android:value=".LunchList" />

这个也是和搜索相关,上面两个是通过intent_filter过滤接收到intent,以及接收到intent之后显示出来的搜索框的布局,但那样只是在你注册了meta-data节点的activity里面才能执行搜索,如果想要在任意一个activity里面都能启动搜索框架,就要加上这个,这个第一行也是给定的,第二行则用来指定是由哪一个activity响应并执行搜索和显示搜索结果.

				<receiver android:name=".AppWidget"
						android:label="@string/app_name"
						android:icon="@drawable/icon">
						<intent-filter>
								<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
								<category android:name="android.intent.category.DEFAULT" />
						</intent-filter>
						<meta-data
								android:name="android.appwidget.provider"
								android:resource="@xml/widget_provider" />
				</receiver>

这段代码中:注册的是一个Widget,其中第二行是widget的标题,第三行是它的图标,

<intent-filter>
		<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
		<category android:name="android.intent.category.DEFAULT" />
</intent-filter>

这个跟最上面的类似,就是注册了intent的过滤器,过滤widget的更新action,第三行在上面解释过了,这里的更新actiong是放在隐式intent里面的,所以要加上第三行

<meta-data
	android:name="android.appwidget.provider"
	android:resource="@xml/widget_provider" />

这个则是对widget的参数配置,第二行是指定的,第三行就是我们自定义的widget参数,放在res/xml下,这里的配置如下:res/xml/widget_provider.xml

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
	 android:minWidth="300dip"
	 android:minHeight="79dip"
	 android:updatePeriodMillis="1800000"
	 android:initialLayout="@layout/widget"
/>

二三四行分别是宽高和更新频率,第五行则是该widget的具体布局,布局方式与layout里的其他布局方式一样:res/layout/widget.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:layout_height="fill_parent"
	android:background="@drawable/widget_frame"
>
	<TextView android:id="@+id/name"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_centerVertical="true"
		android:layout_alignParentLeft="true"
		android:layout_toLeftOf="@+id/next"
		android:textSize="10pt"
		android:textColor="#FFFFFFFF"
	/>
	<ImageButton android:id="@+id/next"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_centerVertical="true"
		android:layout_alignParentRight="true"
		android:src="@drawable/ff"
	/>
</RelativeLayout>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics