Android launcher2 讓Hotseat/底部菜單欄的圖標顯示標題

Launcher2的hotseat中的圖標是不帶標題,有些人可能覺得不夠美觀或者體驗不好,這裏我嘗試地去找了一下可能原因,Hotseat之所以沒能顯示標題,可能由於以下因素:

1、hotseat的高度不夠高

2、hotseat的標題沒有設置

3、hotseat的標題被隱藏起來了

好了大概的原因就這些,根據以下步驟修改就行了。

          

1、Hotseat.java,找到resetLayout()方法,添加 allAppsButton.setText(R.string.all_apps_button_label);

 


 
  1. void resetLayout() {

  2. mContent.removeAllViewsInLayout();

  3.  
  4. Context context = getContext();

  5. LayoutInflater inflater = LayoutInflater.from(context);

  6. BubbleTextView allAppsButton = (BubbleTextView) inflater.inflate(

  7. R.layout.application, mContent, false);

  8. allAppsButton.setCompoundDrawablesWithIntrinsicBounds(null, context

  9. .getResources().getDrawable(R.drawable.all_apps_button_icon),

  10. null, null);

  11. allAppsButton.setContentDescription(context

  12. .getString(R.string.all_apps_button_label));

  13. //添加

  14. allAppsButton.setText(R.string.all_apps_button_label);

  15.  
  16. allAppsButton.setOnTouchListener(new View.OnTouchListener() {

  17. @Override

  18. public boolean onTouch(View v, MotionEvent event) {

  19. if (mLauncher != null

  20. && (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {

  21. mLauncher.onTouchDownAllAppsButton(v);

  22. }

  23. return false;

  24. }

  25. });


 

 

2、CellLayout.java,找到addViewToCellLayout()方法,註釋掉  if (child instanceof BubbleTextView) {}部分

 


 
  1. public boolean addViewToCellLayout(View child, int index, int childId, LayoutParams params,

  2. boolean markCells) {

  3. final LayoutParams lp = params;

  4.  
  5. // Hotseat icons - remove text

  6. // if (child instanceof BubbleTextView) {

  7. // BubbleTextView bubbleChild = (BubbleTextView) child;

  8. //

  9. // Resources res = getResources();

  10. // if (mIsHotseat) {

  11. // bubbleChild.setTextColor(res.getColor(android.R.color.transparent));

  12. // } else {

  13. // bubbleChild.setTextColor(res.getColor(R.color.workspace_icon_text_color));

  14. // }

  15. // }

  16.  
  17. child.setScaleX(getChildrenScale());

  18. child.setScaleY(getChildrenScale());

 

3、分別修改res/values/dimens.xml、res/values-land/dimens.xml、res/values-sw600dp/dimens.xml這3個dimens中的hotseat_cell_height的值,這裏我是統一給他們加30dp,你們可以根據實際情況修改。

做完以上幾步後,大功告成。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章