public void setHomeButtonEnabled(boolean enable) { mHomeLayout.setEnabled(enable); mHomeLayout.setFocusable(enable); // Make sure the home button has an accurate content description for accessibility. if (!enable) { mHomeLayout.setContentDescription(null); } else if ((mDisplayOptions & ActionBar.DISPLAY_HOME_AS_UP) != 0) { mHomeLayout.setContentDescription( mContext.getResources().getText(R.string.abs__action_bar_up_description)); } else { mHomeLayout.setContentDescription( mContext.getResources().getText(R.string.abs__action_bar_home_description)); } }
public ActionBarView(Context context, AttributeSet attrs) { super(context, attrs); // Background is always provided by the container. setBackgroundResource(0); TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.SherlockActionBar, R.attr.actionBarStyleABS, 0); ApplicationInfo appInfo = context.getApplicationInfo(); PackageManager pm = context.getPackageManager(); mNavigationMode = a.getInt( R.styleable.SherlockActionBar_navigationModeABS, ActionBar.NAVIGATION_MODE_STANDARD); mTitle = a.getText(R.styleable.SherlockActionBar_titleABS); mSubtitle = a.getText(R.styleable.SherlockActionBar_subtitleABS); mLogo = a.getDrawable(R.styleable.SherlockActionBar_logoABS); if (mLogo == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { if (context instanceof Activity) { // Even though native methods existed in API 9 and 10 they don't work // so just parse the manifest to look for the logo pre-Honeycomb final int resId = ResourcesCompat.loadLogoFromManifest((Activity) context); if (resId != 0) { mLogo = context.getResources().getDrawable(resId); } } } else { if (context instanceof Activity) { try { mLogo = pm.getActivityLogo(((Activity) context).getComponentName()); } catch (NameNotFoundException e) { Log.e(TAG, "Activity component name not found!", e); } } if (mLogo == null) { mLogo = appInfo.loadLogo(pm); } } } mIcon = a.getDrawable(R.styleable.SherlockActionBar_iconABS); if (mIcon == null) { if (context instanceof Activity) { try { mIcon = pm.getActivityIcon(((Activity) context).getComponentName()); } catch (NameNotFoundException e) { Log.e(TAG, "Activity component name not found!", e); } } if (mIcon == null) { mIcon = appInfo.loadIcon(pm); } } final LayoutInflater inflater = LayoutInflater.from(context); final int homeResId = a.getResourceId(R.styleable.SherlockActionBar_homeLayoutABS, R.layout.abs__action_bar_home); mHomeLayout = (HomeView) inflater.inflate(homeResId, this, false); mExpandedHomeLayout = (HomeView) inflater.inflate(homeResId, this, false); mExpandedHomeLayout.setUp(true); mExpandedHomeLayout.setOnClickListener(mExpandedActionViewUpListener); mExpandedHomeLayout.setContentDescription( getResources().getText(R.string.abs__action_bar_up_description)); mTitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_titleTextStyleABS, 0); mSubtitleStyleRes = a.getResourceId(R.styleable.SherlockActionBar_subtitleTextStyleABS, 0); mProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_progressBarStyleABS, 0); mIndeterminateProgressStyle = a.getResourceId(R.styleable.SherlockActionBar_indeterminateProgressStyleABS, 0); mProgressBarPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_progressBarPaddingABS, 0); mItemPadding = a.getDimensionPixelOffset(R.styleable.SherlockActionBar_itemPaddingABS, 0); setDisplayOptions(a.getInt(R.styleable.SherlockActionBar_displayOptionsABS, DISPLAY_DEFAULT)); final int customNavId = a.getResourceId(R.styleable.SherlockActionBar_customNavigationLayoutABS, 0); if (customNavId != 0) { mCustomNavView = inflater.inflate(customNavId, this, false); mNavigationMode = ActionBar.NAVIGATION_MODE_STANDARD; setDisplayOptions(mDisplayOptions | ActionBar.DISPLAY_SHOW_CUSTOM); } mContentHeight = a.getLayoutDimension(R.styleable.SherlockActionBar_heightABS, 0); a.recycle(); mLogoNavItem = new ActionMenuItem(context, 0, android.R.id.home, 0, 0, mTitle); mHomeLayout.setOnClickListener(mUpClickListener); mHomeLayout.setClickable(true); mHomeLayout.setFocusable(true); }