在SystemUI添加虚拟按键

我们想要在volume、back、menu同一排添加一个虚拟按键,并且触发一个应用;
  1、首先我们要找到这些虚拟按键的位置:\frameworks\base\packages\SystemUI\res\layout-sw600dp\navigation_bar.xml
  2、横屏时,最左边的RelativeLayout 中添加:
   ......
   <FrameLayout android:id="@+id/rot0"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        >
        <RelativeLayout
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:layout_gravity="left">
                 <!-- add Await-->
                 <com.android.systemui.statusbar.policy.KeyButtonView
         android:id="@+id/img_logo"
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:layout_gravity="left|center_vertical"
                     android:paddingLeft="5.0dip"
                     android:src="@drawable/img_logo"
                     systemui:glowBackground="@drawable/ic_sysbar_highlight"
                     android:contentDescription="@string/accessibility_recent"/>
                 <!--end-->
             </RelativeLayout>
    ......
    竖屏时,最左边的RelativeLayout 中添加:
    ......
     <FrameLayout android:id="@+id/rot90"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:visibility="gone"
        android:paddingTop="0dp"
        >
  
  <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left">
           
            <com.android.systemui.statusbar.policy.KeyButtonView
    android:id="@+id/img_logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:paddingLeft="5.0dip"
                android:src="@drawable/img_logo"
                systemui:glowBackground="@drawable/ic_sysbar_highlight"
                android:contentDescription="@string/accessibility_recent"/>
           
        </RelativeLayout>
    ......
   3、添加java触发代码:\frameworks\base\packages\SystemUI\src\com\android\systemui\statusbar\phone\NavigationBarView.java
    (1)  ......
      import android.content.ComponentName;//add Await
     
    (2) //add Await 返回图标
    public View getImgLogo(){
            return mCurrentView.findViewById(R.id.img_logo);
       }
    (3)添加触发应用:
        public void setNavigationIconHints(int hints, boolean force) {
        if (!force && hints == mNavigationIconHints) return;
        final boolean backAlt = (hints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0;
        if ((mNavigationIconHints & StatusBarManager.NAVIGATION_HINT_BACK_ALT) != 0 && !backAlt) {
            mTransitionListener.onBackAltCleared();
        }
        if (DEBUG) {
            android.widget.Toast.makeText(mContext,
                "Navigation icon hints = " + hints,
                500).show();
        }

        mNavigationIconHints = hints;

        ((ImageView)getBackButton()).setImageDrawable(backAlt
                ? (mVertical ? mBackAltLandIcon : mBackAltIcon)
                : (mVertical ? mBackLandIcon : mBackIcon));

        ((ImageView)getRecentsButton()).setImageDrawable(mVertical ? mRecentLandIcon : mRecentIcon);
      //add Await 
  ((ImageView)getImgLogo()).setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    Intent mIntent = new Intent( );
    mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    ComponentName comp = new ComponentName("com.xintu.navcity", "com.xintu.navcity.MainActivity");
    mIntent.setComponent(comp);
    mIntent.setAction("android.intent.action.VIEW");
    mContext.startActivity(mIntent);
    
   }
  });
      setDisabledFlags(mDisabledFlags, true);
    }

你可能感兴趣的:(navigation_bar,在SystemUI添加虚拟按键)