• Clover launcher


    <intent-filter>
    </intent-filter>

    中添加

    <category android:name="android.intent.category.HOME" />
     <category android:name="android.intent.category.DEFAULT" />

    作用
    把应用程序作为home

    知识点:GridView 显示数据表格(一种控件) 宫格布局

    GridView属性说明
    android:columnWidth 设置列的宽度
    android:horizontalSpacing两列之间的间距
    android:verticalSpacing两行之间的间距
    android:numColumns设置列数。取值有2种。
    (01)可以设置为数字,比如:”2”表示有两列。
    (02)可以设置为“auto_fit”,表示根据“屏幕宽
    度”和“GridView宽度”来动态匹配。
    渲染问题解决办法:在项目项目中找到 app src main res values styles.xml文件,把下面这一栏

    <style name =“AppTheme”parent =“Theme.AppCompat.Light.DarkActionBar”> 

    改为

    <style name =“AppTheme”parent =“Base.Theme.AppCompat.Light.DarkActionBar”> 

    https://blog.csdn.net/dafei93/article/details/80471615

    activity_main.xml
    加入宫格布局 GridView

    <GridView
            android:id="@+id/apps_list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="180dp"
            android:numColumns="4"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    MainActivity.java

    package com.example.administrator.cloverlauncher;
    
    import java.util.List;
    
    import android.app.Activity;
    import android.content.ComponentName;
    import android.content.Intent;
    import android.content.pm.ResolveInfo;
    import android.os.Bundle;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.BaseAdapter;
    import android.widget.GridView;
    import android.widget.ImageView;
    
    public class MainActivity extends Activity {
        private List<ResolveInfo> mApps;
        private GridView mGrid;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            loadApps();
            setContentView(R.layout.activity_main);
            mGrid = (GridView) findViewById(R.id.apps_list);
            mGrid.setAdapter(new AppsAdapter());
    
            mGrid.setOnItemClickListener(listener);
        }
    
        private OnItemClickListener listener = new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,long id) {
                ResolveInfo info = mApps.get(position);
    
                //该应用的包名
                String pkg = info.activityInfo.packageName;
                //应用的主activity类
                String cls = info.activityInfo.name;
    
                ComponentName componet = new ComponentName(pkg, cls);
    
                Intent i = new Intent();
                i.setComponent(componet);
                startActivity(i);
            }
    
        };
    
    
        private void loadApps() {
            Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
            mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    
            mApps = getPackageManager().queryIntentActivities(mainIntent, 0);
        }
    
    
    
        public class AppsAdapter extends BaseAdapter {
            public AppsAdapter() {
            }
    
            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i;
    
    
                if (convertView == null) {
                    i = new ImageView(MainActivity.this);
                    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
                    i.setLayoutParams(new GridView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                } else {
                    i = (ImageView) convertView;
                }
    
                ResolveInfo info = mApps.get(position);
                i.setImageDrawable(info.activityInfo.loadIcon(getPackageManager()));
    
                return i;
            }
    
            public final int getCount() {
                return mApps.size();
            }
    
            public final Object getItem(int position) {
                return mApps.get(position);
            }
    
            public final long getItemId(int position) {
                return position;
            }
        }
    
    }
    
  • 相关阅读:
    python day2 省市三级联动
    Dynamics CRM绑定表单查看当前表单的数据参数传递
    Dynamics CRM制作报表的时候让用户可以用自己的权限浏览数据
    Sql Server Report Service访问服务页面503解决方法
    Dynamics CRM报表无法访问提示“报表服务器无法访问或使用加密密钥。你可能需要将服务器添加到扩展组,或重新导入”
    Dynamics CRM报表点击自动运行方法
    C#委托的学习了解
    Google不兼容ShowModalDialog()弹出对话框的解决办法
    Dynamics CRM报表提示rsProcessingAborted解决方法
    Dynamics CRM邮箱配置
  • 原文地址:https://www.cnblogs.com/ZCWang/p/12507487.html
Copyright © 2020-2023  润新知