先看效果图

这个是我们自己的apk点击之后的效果

下边是布局文件

activity_main.xml主布局文件

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

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    tools:context=".MainActivity"

    android:orientation="vertical">

<TextView 

   android:layout_width="match_parent"

   android:layout_height="wrap_content"

   android:gravity="center"

   android:layout_marginTop="15dp"

   android:text="@string/app_name"/>





    <GridView 

        android:id="@+id/allapps"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"/>





</LinearLayout>

我用一个GridView 做容器

下边是单个item布局文件

application_layout.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"

    android:gravity="center" 

    >

    

<ImageView 

   android:id="@+id/app_icon"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   android:layout_marginTop="15dp"/>



<TextView

   android:id="@+id/app_title"

   android:layout_width="wrap_content"

   android:layout_height="wrap_content"

   android:textSize="12sp"

   android:gravity="center"/>

</LinearLayout>

下边是AndroidManifest.xml。这个里边有几个和普通apk不同的地方

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

>

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

    package="com.wind.lancherdemo"

    android:versionCode="1"

    android:versionName="1.0" >





    <uses-sdk

        android:minSdkVersion="17"

        android:targetSdkVersion="17" />





    <application

        android:allowBackup="true"

        android:icon="@drawable/ic_launcher"

        android:label="@string/app_name" >

        <activity

            android:name="com.wind.lancherdemo.MainActivity"

            android:theme="@android:style/Theme.Dialog"                  <!--这个更改app theme为Dialog-->

            android:label="@string/app_name" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />





                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

    </application>





</manifest>

下边是源文件

package com.wind.lancherdemo;





import java.util.ArrayList;

import java.util.Collections;

import java.util.List;





import android.app.Activity;

import android.content.ComponentName;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.content.pm.ResolveInfo;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.view.Window;

import android.widget.AdapterView;

import android.widget.AdapterView.OnItemClickListener;

import android.widget.BaseAdapter;

import android.widget.GridView;

import android.widget.ImageView;

import android.widget.TextView;





public class MainActivity extends Activity implements OnItemClickListener{

private GridView mGridView;

private Context mContext;

private PackageManager mPackageManager;

private List<ResolveInfo> mAllApps;

private List<ResolveInfo> mShowApps = new ArrayList<ResolveInfo>();

private static final String[] mShowAppPkgNames = {"com.android.contacts","com.android.mms","com.android.browser"};  //这个地方能够加入我们须要过滤的apk包名

  @Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.activity_main);



setupViews();

}













private void setupViews() {

mContext = MainActivity.this;

mPackageManager = getPackageManager();

mGridView = (GridView)findViewById(R.id.allapps);

bindAllApps();



mGridView.setAdapter(new GridItemAdapter(mContext, mShowApps));  //这个地方时设置GridView的适配器,不懂的能够去网上搜下详细教程

mGridView.setNumColumns(3);

mGridView.setOnItemClickListener(this);

}













private void bindAllApps() {

Intent mainIntent = new Intent(Intent.ACTION_MAIN,null);

mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

mAllApps = mPackageManager.queryIntentActivities(mainIntent, 0);//这个地方就是我们依据我们安装的全部apk过滤出我们想要的apk,这样做的目的是你删除了某个我们须要的应用。我们的程序依旧正常

for (ResolveInfo app_item : mAllApps) {

String pkg = app_item.activityInfo.packageName;

for (int i = 0; i < mShowAppPkgNames.length; i++) {

if(mShowAppPkgNames[i].equals(pkg)) {

mShowApps.add(app_item);

}

}

}

Collections.sort(mShowApps, new ResolveInfo.DisplayNameComparator(mPackageManager));

}











//这个是依据我们的点击进入到详细的应用

@Override

public void onItemClick(AdapterView<?

> parent, View view, int position, long id) {

ResolveInfo res = mShowApps.get(position);

String pkg = res.activityInfo.packageName;

String cls = res.activityInfo.name;



ComponentName component = new ComponentName(pkg, cls);



Intent i = new Intent();

i.setComponent(component);

startActivity(i);

}

//这个地方是我们重写我们的GridView适配器

private class GridItemAdapter extends BaseAdapter{

private Context context;

private List<ResolveInfo> resInfo;







public GridItemAdapter(Context context, List<ResolveInfo> resInfo) {

this.context = context;

this.resInfo = resInfo;

}





@Override

public int getCount() {

// TODO Auto-generated method stub

return resInfo.size();

}





@Override

public Object getItem(int position) {

// TODO Auto-generated method stub

return resInfo.get(position);

}





@Override

public long getItemId(int position) {

// TODO Auto-generated method stub

return position;

}



//这个地方用ViewHolder的目的是不用我们每次重构我们的convertView 及寻找ImageView和TextView,能够提高app执行速度

@Override

public View getView(int position, View convertView, ViewGroup parent) {

ViewHolder holder = null;



if (convertView == null) {

convertView = LayoutInflater.from(context).inflate(R.layout.application_layout, null);

holder = new ViewHolder();

holder.mAppIcon = (ImageView)convertView.findViewById(R.id.app_icon);

holder.mAppTitle = (TextView)convertView.findViewById(R.id.app_title);

convertView.setTag(holder);

} else {

holder = (ViewHolder)convertView.getTag();

}



ResolveInfo res = resInfo.get(position);

holder.mAppIcon.setImageDrawable(res.loadIcon(mPackageManager));

holder.mAppTitle.setText(res.loadLabel(mPackageManager).toString());



return convertView;

}



private class ViewHolder {

ImageView mAppIcon;

TextView mAppTitle;

}

}





}

android中怎么把自己须要的app启动图标集中到一个弹出框中的更多相关文章

  1. 在IOS11中position:fixed弹出框中的input出现光标错位的问题

    问题出现的背景: 在IOS11中position:fixed弹出框中的input出现光标错位的问题 解决方案 一.设计交互方面最好不要让弹窗中出现input输入框: 二.前端处理此兼容性的方案思路: ...

  2. 苹果手机iOS11中fixed弹出框中input光标错位问题

    最近遇到了一个移动前端的BUG:手机弹出框中的输入框focus时光标可能会错位. 刚开始时我完全不知道错误原因是什么,在电脑上调试时完全没有问题,手机上出现问题时也没有找到规律.后来在网上搜索了大量的 ...

  3. 弹出框中选项卡的运用(easyUI)

    先看一下页面效果: 此处有两个知识点:一个是弹出框的运用,一个是选项卡的运用 分析一下该HTML代码,最外面一个div是弹出框的,默认是关闭状态,可通过ID来控制弹出框的开关,该div的样式是easy ...

  4. 弹出框中的AJAX分页

    $(function() { $("body").on("click",".set-topic",function(){ /*获取所有题目接 ...

  5. 使用easeui dialog弹出框中使用CKeditor多次加载后无法编辑问题

    问题呈现:弹出框页面 <tr class="addtr"> <th>内容</th> <td> <!-- <textare ...

  6. firefox浏览器中 bootstrap 静态弹出框中select下拉框不能弹出(解决方案)

    问题出现场景1: 在firefox浏览器中在bootstrap弹出的modal静态框中再次弹出一个静态框时 select下拉框不能弹出选项 解决方案:去掉最外层静态框的 tabindex=" ...

  7. iOS8 UIAlertController弹出框中添加视图(例如日期选择器等等)

    UIDatePicker *datePicker = [[UIDatePicker alloc] init]; datePicker.datePickerMode = UIDatePickerMode ...

  8. mvc 在弹出框中实现文件下载

    var myParent = parent.parent.parent.parent.parent.parent.parent.parent.parent.parent.parent.parent; ...

  9. IOS中position:fixed弹出框中的input出现光标错位的问题

    解决方案是 在弹框出现的时候给body添加fixed <style type="text/css"> body{ position: fixed; width: 100 ...

随机推荐

  1. [Oracle] - 性能优化工具(4) - AWRDD

    AWRDD是用于比較两个AWR快照,从而获得不同一时候期的性能. 运行例如以下语句获得AWRDD: @?/rdbms/admin/awrddrpt.sql 2025 23 2月 2014 07:12 ...

  2. 每天一个JavaScript实例-html5拖拽

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  3. 聊天demo SignalR

    1首先这个demo是针对 net版本是4.5的  SignalR   获取的是2.2的 2新建一个mvc项目 3  Nuget  搜索 SignalR   安装如图的一项 4新建一个 集线器类 修改新 ...

  4. 国庆去学校的国际象棋(Latex)

    国庆节去学棋与朋友. 看国外的网站更有趣的事情. 很快打下来. 首先效应: 嘿嘿  代码来了哟: \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc ...

  5. Sencha Architect 2 的使用

    俗话说的好, 工欲善其事必先利其器, 用Sencha开发的语言, 自己可能不太熟悉, 写出来很麻烦, 于是给大家介绍一个工具. 启动程序第一个界面: 单击第一个Go按钮, 创建一个项目.进入以后, 单 ...

  6. 第4周 页面限制8060 bytes

    原文:第4周 页面限制8060 bytes 恭喜您!在你面前就只剩下几页了,然后你就可以完成第1个月的SQL Server性能调优培训了.今天我将讲下页的一些限制,还有为什么你会喜欢这些限制,同时也会 ...

  7. POJ 3684 Priest John&#39;s Busiest Day 2-SAT+输出路径

    强连通算法推断是否满足2-sat,然后反向建图,拓扑排序+染色. 一种选择是从 起点開始,还有一种是终点-持续时间那个点 開始. 若2个婚礼的某2种时间线段相交,则有矛盾,建边. easy出错的地方就 ...

  8. Java 过滤器的作用

    Servlet API 非常久曾经就已成为企业应用开发的基石,而 Servlet 过滤器则是对 J2EE 家族的相对较新的补充.在 J2EE 探索者 系列文章的最后一篇中,作者 Kyle Gabhar ...

  9. 读取 raspberrypi 的cpu和gpu温度

    #!/usr/bin/env python # -*- coding: utf-8 -*- import requests import json import time import command ...

  10. Mono for Andriod学习与实践(1)— 初体验

    对于Andriod的开发者来说,相信Java语言是第一选择,可是对于.Net开发者来说,要想利用C#在Andriod平台上开发,Mono提供了相应的开发平台来实现,Mono for Andriod就是 ...