android状态栏加ImageView

来源:互联网 发布:vb如何隐藏控件菜单栏 编辑:程序博客网 时间:2024/05/16 08:29

\android4.0\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\tablet 

定义 ImageView switchbutton;

switchbutton= (ImageView)sb.findViewById(R.id.swilanucher);
  
  switchbutton.setOnClickListener(new OnClickListener(){

   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    Log.e(TAG,"click by pcc+++++++++++++++++++++++++++");
   }
      
     });

 

\android4.0\frameworks\base\packages\SystemUI\res\layout-sw600dp 

        />
                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
                    android:layout_width="80dip"
                    android:layout_height="match_parent"
                    android:src="@drawable/ic_sysbar_recent"
                    android:contentDescription="@string/accessibility_recent"
                    systemui:glowBackground="@drawable/ic_sysbar_highlight"
                    />
               
               
    <ImageView
        android:id="@+id/swilanucher"
        android:layout_width="80dip"
        android:layout_height="wrap_content"
        android:src="@drawable/statusbar_bh" 
   />
                    <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/volume_down"
        android:layout_width="80dip"
        android:layout_height="match_parent"
        android:src="@drawable/ic_sysbar_volume_down"
        systemui:keyCode="25"
        systemui:glowBackground="@drawable/ic_sysbar_highlight"
        android:visibility="gone"
        />
                       
                <com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/volume_up"
        android:layout_width="80dip"
        android:layout_height="match_parent"
        android:src="@drawable/ic_sysbar_volume_up"
        systemui:keyCode="24"
        systemui:glowBackground="@drawable/ic_sysbar_highlight"
        android:visibility="gone"
        />

图片资源:

\android4.0\frameworks\base\packages\SystemUI\res\drawable-sw600dp-mdpi

 

 

设置默认launcher 并启动:

import android.app.ActivityThread;

import android.content.pm.IPackageManager;

 

 

 

switchbutton.setOnClickListener(new OnClickListener(){
       
        @Override
        public void onClick(View arg0) {
           // TODO Auto-generated method stub
                Log.e(TAG,"click by pcc+++++++++++++++++++++++++++");
    //Intent intents =  new Intent(Intent.ACTION_MAIN, null);
                 /*intents.addCategory(Intent.CATEGORY_HOME);
                 intents.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
                | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
     
    ComponentName component = new ComponentName("com.mofing", "com.mofing.mos.QtActivity");//packageName:第三方应用程序的包名,className第三方应用程序的类名
                intents.setComponent(component);
    startActivityForResult(intents, 1);
    startActivity(intents);
    intents.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);*/
    IPackageManager pm = ActivityThread.getPackageManager();
    Intent intent = new Intent(Intent.ACTION_MAIN);
                intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                List<ResolveInfo> list = new ArrayList<ResolveInfo>();
                try {
                    list = pm.queryIntentActivities(intent,
                        intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                        PackageManager.MATCH_DEFAULT_ONLY);
                }catch (RemoteException e) {
                    throw new RuntimeException("Package manager has died", e);
                } 
                // get all components and the best match
                IntentFilter filter = new IntentFilter();
                filter.addAction(Intent.ACTION_MAIN);
                filter.addCategory(Intent.CATEGORY_HOME);
                filter.addCategory(Intent.CATEGORY_DEFAULT);
                final int N = list.size();
                ComponentName[] set = new ComponentName[N];
                int bestMatch = 0;
                for (int i = 0; i < N; i++) {
                    ResolveInfo r = list.get(i);
                    set[i] = new ComponentName(r.activityInfo.packageName,
                                    r.activityInfo.name);
                    if (r.match > bestMatch) bestMatch = r.match;
                }
                // add the default launcher as the preferred launcher
                ComponentName launcher = new ComponentName("com.mofing", "com.mofing.mos.QtActivity");
                try {
                    pm.addPreferredActivity(filter, bestMatch, set, launcher);
                } catch (RemoteException e) {
                    throw new RuntimeException("Package manager has died", e);
                }
    context.startActivity(intent);  
    
            }
     
        });

原创粉丝点击