•多个视图属性的集合, 在写布局时, 当多个视图有不少相同的属性时, 可以把这些相同的属性放在一起在styles.xml中定义成一个Style, 而在布局文件中使用@style/style_name统一引用 •作用: •复用视图标签属性 •目标: •针对的是窗口中的某些视图 •系统样式: •Android也定义了些系统样式可以使用 •使用系统样式: @android:style/xxx
wrap_content wrap_content center_vertical 20sp @android:drawable/star_big_on 10dp#FF0000————————————————————————————————————————————————————主题(theme)•理解: •主题的本质也是style•在styles.xml中定义, 在manifest.xml中引用•作用: •复用视图标签属性•目标: •针对整个应用或某个Activity的界面•系统常用主题:•@android:style/Theme.Light.NoTitleBar : 没有标题 •@android:style/Theme.Light.NoTitleBar.Fullscreen: 全屏•@android:style/Theme.Dialog : 对话框————————————————————————————————————————————————————显示所有应用列表•功能描述:•此功能是手机卫士程序管理模块的一部分•它以列表的形式列出手机中所有应用的信息•点击某一项,提示选择的应用的名称•长按某一项,删除当前行••主要技术:•应用的整体布局与Item的布局•获取手机中所有安装的应用信息集合(已定义)•使用BaseAdapter显示列表信息•ListView的item点击响应scaleType=“fitXY” //图片充满View的宽度minHeight=“70dp” //最小高度package com.example.app03_allapp;import java.util.ArrayList;import java.util.List;import android.app.Activity;import android.content.Intent;import android.content.pm.PackageManager;import android.content.pm.ResolveInfo;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;public class MainActivity extends Activity {private ListView Iv_main;//列表控件private Listdata;//数据源 ,数据的集合private AppAdapter adapter;//适配器@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);//初始化成员变量Iv_main=(ListView) findViewById(R.id.lv_main);data = getAllAppInfos();adapter = new AppAdapter();//显示列表Iv_main.setAdapter(adapter);}/* * 得到手机中所有应用信息的列表 * AppInfo * Drawable icon * String appName * String packageName */protected ListgetAllAppInfos() {Listlist = new ArrayList();// 得到应用的packgeManagerPackageManager packageManager = getPackageManager();// 创建一个主界面的intentIntent intent = new Intent();intent.setAction(Intent.ACTION_MAIN);intent.addCategory(Intent.CATEGORY_LAUNCHER);// 得到包含应用信息的列表ListResolveInfos = packageManager.queryIntentActivities(intent, 0);// 遍历for (ResolveInfo ri : ResolveInfos) {// 得到包名String packageName = ri.activityInfo.packageName;// 得到图标Drawable icon = ri.loadIcon(packageManager);// 得到应用名称String appName = ri.loadLabel(packageManager).toString();// 封装应用信息对象AppInfo appInfo = new AppInfo(icon, appName, packageName);// 添加到listlist.add(appInfo);}return list;}class AppAdapter extends BaseAdapter{@Overridepublic int getCount() {// TODO Auto-generated method stubreturn data.size();}@Overridepublic Object getItem(int position) {// TODO Auto-generated method stubreturn data.get(position);}@Overridepublic long getItemId(int position) {// TODO Auto-generated method stubreturn position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolder holder = null;if(convertView == null){convertView = View.inflate(MainActivity.this, R.layout.item_main,null);holder = new ViewHolder();//2.得到当前行需要更新的子View对象holder.imageView = (ImageView) convertView.findViewById(R.id.iv_item_icon);holder.textView = (TextView) convertView.findViewById(R.id.tv_item_name);convertView.setTag(holder);}else{holder = (ViewHolder) convertView.getTag();}//3.得到当前行的数据对象AppInfo appInof = data.get(position);//4.给视图对象绑定数据holder.imageView.setImageDrawable(appInof.getIcon());holder.textView.setText(appInof.getAppName());//5.返回convertViewreturn convertView;}class ViewHolder{ImageView imageView;TextView textView;}}}package com.example.app03_allapp;import android.graphics.drawable.Drawable;public class AppInfo {private Drawable icon;//应用图标,图标对象private String appName;//应用名称private String packageName;//包名public AppInfo() {super();}public Drawable getIcon() {return icon;}public void setIcon(Drawable icon) {this.icon = icon;}public String getAppName() {return appName;}public void setAppName(String appName) {this.appName = appName;}public String getPackageName() {return packageName;}public void setPackageName(String packageName) {this.packageName = packageName;}public AppInfo(Drawable icon, String appName, String packageName) {super();this.icon = icon;this.appName = appName;this.packageName = packageName;}} ?xml version="1.0" encoding="utf-8"?————————————————————————————————————————————————————手机卫士主界面•功能描述:•此功能是手机卫士主界面功能的一部分•以3*3网格的形式显示功能模块列表•点击某一项, 提示选择的功能模块的名称••主要技术:•应用的整体布局与Item的布局•利用BaseAdapter在GridView中网格列表信息•GridView的item点击响应numColums=“3” //列数verticalSpacing=“10dp” //item之间在垂直方向的间距package com.example.app04_gridview;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.MenuItem;import android.widget.GridView;public class MainActivity extends Activity {private GridView gv_main;private MainAdapter adapter;String [] names=new String[]{"手机防盗","通讯卫士","软件管理","流量管理","进程管理","手机杀毒","22","33","44"};int [] icons=new int[]{R.drawable.widget01,R.drawable.widget02,R.drawable.widget03,R.drawable.widget04,R.drawable.widget05,R.drawable.widget06,R.drawable.widget07,R.drawable.widget08,R.drawable.widget09};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);gv_main=(GridView) findViewById(R.id.gv_main);adapter=new MainAdapter(MainActivity.this,names,icons);gv_main.setAdapter(adapter);}}package com.example.app04_gridview;import android.content.Context;import android.graphics.drawable.Drawable;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.TextView;public class MainAdapter extends BaseAdapter{private String[] names;private int[] icons;private Context context; public MainAdapter(Context context,String[] names,int[] icons) { this.context=context; this.names=names; this.icons=icons; }@Overridepublic int getCount() {return names.length;}@Overridepublic Object getItem(int position) {return names[position];}@Overridepublic long getItemId(int position) {return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ViewHolser holder=null;if (convertView==null) {convertView=View.inflate(context, R.layout.item_main, null);holder=new ViewHolser();holder.imageView = (ImageView) convertView.findViewById(R.id.iv_id1);holder.textView = (TextView) convertView.findViewById(R.id.tv_id1);convertView.setTag(holder); }else{holder = (ViewHolser) convertView.getTag();}holder.imageView.setImageResource(icons[position]);holder.textView.setText(names[position]);return convertView;} class ViewHolser{ ImageView imageView; TextView textView; }}?xml version="1.0" encoding="utf-8"??xml version="1.0" encoding="utf-8"?