Java Code Examples for android.support.v7.widget.Toolbar#setSubtitleTextColor()

The following examples show how to use android.support.v7.widget.Toolbar#setSubtitleTextColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From PracticeCode with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toast.makeText(this, "喵佩罗娜!", Toast.LENGTH_SHORT).show();
    XSCHelper.getInstance().loadProjListFromLocal(this);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(Color.LTGRAY);
    toolbar.setSubtitle(UserInfoBasic.nickName);
    toolbar.setSubtitleTextColor(Color.LTGRAY);
    setSupportActionBar(toolbar);

    menuFadeAdapter = new MenuFadeAdapter(toolbar);
    menuFadeAdapter.setColor(ToolbarColor);
    menuFadeAdapter.setMaxAlpha(255);
    menuFadeAdapter.saveAndNotifySettingsChanged();

    toolBarFadeAdapter = new ToolBarFadeAdapter(toolbar);
    toolBarFadeAdapter.setColor(ToolbarColor);
    toolBarFadeAdapter.setAlpha(255, 0);
    toolBarFadeAdapter.setMenuAdapter(menuFadeAdapter);
    toolBarFadeAdapter.saveAndNotifySettingsChanged();

    initWidgets();
    initSettings();
}
 
Example 2
Source File: LockedCompatActivity.java    From LolliPin with MIT License 5 votes vote down vote up
private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.id_toolbar);
    setSupportActionBar(toolbar);

    toolbar.setTitle("Title");
    toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
    toolbar.setSubtitle("SubTitle");
    toolbar.setSubtitleTextColor(getResources().getColor(android.R.color.white));
    toolbar.setLogo(R.drawable.ic_launcher);
    toolbar.setNavigationIcon(R.drawable.ic_menu_white_36dp);
}
 
Example 3
Source File: ActorToolbar.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter
            = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.SRC_IN);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        doColorizing(v, colorFilter, toolbarIconsColor);
    }

    //Step 3: Changing the color of title and subtitle.
    toolbarView.setTitleTextColor(toolbarIconsColor);
    toolbarView.setSubtitleTextColor(toolbarIconsColor);
}
 
Example 4
Source File: SuntimesActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Override the appearance of views if appThemeOverride is defined.
 * @param context Context
 */
protected void themeViews(Context context)
{
    if (appThemeOverride != null)
    {
        Log.i("themeViews", "Applying theme: " + appThemeOverride.themeName());
        int titleColor = appThemeOverride.getTitleColor();
        int timeColor = appThemeOverride.getTimeColor();
        int textColor = appThemeOverride.getTextColor();
        int disabledColor = ContextCompat.getColor(context, resID_buttonDisabledColor);
        int pressedColor = appThemeOverride.getActionColor();

        Toolbar actionBar = (Toolbar) findViewById(R.id.app_menubar);
        actionBar.setTitleTextColor(titleColor);
        actionBar.setSubtitleTextColor(textColor);

        txt_time.setTextColor(timeColor);
        txt_time_suffix.setTextColor(timeColor);
        txt_timezone.setTextColor(SuntimesUtils.colorStateList(textColor, disabledColor, pressedColor));

        txt_time1_note1.setTextColor(timeColor);
        txt_time1_note2.setTextColor(textColor);
        txt_time2_note1.setTextColor(timeColor);
        txt_time2_note2.setTextColor(textColor);

        txt_datasource.setTextColor(SuntimesUtils.colorStateList(textColor, disabledColor, pressedColor));
        txt_altitude.setTextColor(timeColor);

        color_textTimeDelta = appThemeOverride.getTimeColor();
        card_adapter.setThemeOverride(appThemeOverride);
        card_equinoxSolstice.themeViews(context, appThemeOverride);
    }
}
 
Example 5
Source File: CustomToolbar.java    From Lucid-Browser with Apache License 2.0 5 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 * @param toolbarView toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor) {
	final PorterDuffColorFilter colorFilter
			= new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.SRC_IN);

	for(int i = 0; i < toolbarView.getChildCount(); i++) {
		final View v = toolbarView.getChildAt(i);

		doColorizing(v, colorFilter, toolbarIconsColor);
	}

	//Step 3: Changing the color of title and subtitle.
	toolbarView.setTitleTextColor(toolbarIconsColor);
	toolbarView.setSubtitleTextColor(toolbarIconsColor);
}
 
Example 6
Source File: ToolbarColorizeHelper.java    From IdeaTrackerPlus with MIT License 4 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        //Step 1 : Changing the color of back button (or open drawer button).
        if (v instanceof ImageButton) {
            //Action Bar back button
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }


        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
                //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread, by adding it to the message queue
                            //Won't work otherwise.
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
Example 7
Source File: ToolbarColorizeHelper.java    From RetroMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        //Step 1 : Changing the color of back button (or open drawer button).
        if (v instanceof ImageButton) {
            //Action Bar back button
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }


        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
                //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread, by adding it to the message queue
                            //Won't work otherwise.
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}
 
Example 8
Source File: ToolbarContentTintHelper.java    From APlayer with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public static void setToolbarContentColor(@NonNull Context context, Toolbar toolbar,
    @Nullable Menu menu, final @ColorInt int toolbarContentColor,
    final @ColorInt int titleTextColor, final @ColorInt int subtitleTextColor,
    final @ColorInt int menuWidgetColor) {
  if (toolbar == null) {
    return;
  }

  if (menu == null) {
    menu = toolbar.getMenu();
  }

  toolbar.setTitleTextColor(titleTextColor);
  toolbar.setSubtitleTextColor(subtitleTextColor);

  if (toolbar.getNavigationIcon() != null) {
    // Tint the toolbar navigation icon (e.g. back, drawer, etc.)
    toolbar.setNavigationIcon(
        TintHelper.createTintedDrawable(toolbar.getNavigationIcon(), toolbarContentColor));
  }

  InternalToolbarContentTintUtil.tintMenu(toolbar, menu, toolbarContentColor);
  InternalToolbarContentTintUtil.applyOverflowMenuTint(context, toolbar, menuWidgetColor);

  if (context instanceof Activity) {
    InternalToolbarContentTintUtil
        .setOverflowButtonColor((Activity) context, toolbarContentColor);
  }

  try {
    // Tint immediate overflow menu items
    final Field menuField = Toolbar.class.getDeclaredField("mMenuBuilderCallback");
    menuField.setAccessible(true);
    final Field presenterField = Toolbar.class.getDeclaredField("mActionMenuPresenterCallback");
    presenterField.setAccessible(true);
    final Field menuViewField = Toolbar.class.getDeclaredField("mMenuView");
    menuViewField.setAccessible(true);

    final MenuPresenter.Callback currentPresenterCb = (MenuPresenter.Callback) presenterField
        .get(toolbar);
    if (!(currentPresenterCb instanceof ATHMenuPresenterCallback)) {
      final ATHMenuPresenterCallback newPresenterCb = new ATHMenuPresenterCallback(context,
          menuWidgetColor, currentPresenterCb, toolbar);
      final MenuBuilder.Callback currentMenuCb = (MenuBuilder.Callback) menuField.get(toolbar);
      toolbar.setMenuCallbacks(newPresenterCb, currentMenuCb);
      ActionMenuView menuView = (ActionMenuView) menuViewField.get(toolbar);
      if (menuView != null) {
        menuView.setMenuCallbacks(newPresenterCb, currentMenuCb);
      }
    }

    // OnMenuItemClickListener to tint submenu items
    final Field menuItemClickListener = Toolbar.class
        .getDeclaredField("mOnMenuItemClickListener");
    menuItemClickListener.setAccessible(true);
    Toolbar.OnMenuItemClickListener currentClickListener = (Toolbar.OnMenuItemClickListener) menuItemClickListener
        .get(toolbar);
    if (!(currentClickListener instanceof ATHOnMenuItemClickListener)) {
      final ATHOnMenuItemClickListener newClickListener = new ATHOnMenuItemClickListener(context,
          menuWidgetColor, currentClickListener, toolbar);
      toolbar.setOnMenuItemClickListener(newClickListener);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
}
 
Example 9
Source File: ToolbarActivity.java    From AndroidViewDemo with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ac_toolbar);

    Toolbar toolbar = (Toolbar) findViewById(R.id.ac_toolbar_toolbar);

    // 设置主标题及其颜色
    toolbar.setTitle("AndroidViewDemo");
    toolbar.setTitleTextColor(Color.WHITE);

    // 设置次标题及其颜色
    toolbar.setSubtitle("AigeStudio");
    toolbar.setSubtitleTextColor(Color.LTGRAY);

    // 设置导航按钮
    toolbar.setNavigationIcon(R.drawable.menu);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ToolbarActivity.this, "Navigation", Toast.LENGTH_SHORT).show();
        }
    });
    // 设置Logo图标
    toolbar.setLogo(R.mipmap.ic_launcher);

    // 设置菜单及其点击监听
    toolbar.inflateMenu(R.menu.ac_toolbar_menu);
    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            String result = "";
            switch (item.getItemId()) {
                case R.id.ac_toolbar_copy:
                    result = "Copy";
                    break;
                case R.id.ac_toolbar_cut:
                    result = "Cut";
                    break;
                case R.id.ac_toolbar_del:
                    result = "Del";
                    break;
                case R.id.ac_toolbar_edit:
                    result = "Edit";
                    break;
                case R.id.ac_toolbar_email:
                    result = "Email";
                    break;
            }
            Toast.makeText(ToolbarActivity.this, result, Toast.LENGTH_SHORT).show();
            return true;
        }
    });
}
 
Example 10
Source File: ContributorsActivity.java    From GithubContributorsLib with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {

    Bundle bundle = getIntent().getExtras();

    String token = null;
    String repositoryUrl = null;

    if (bundle == null || !bundle.containsKey(Contributors.BUNDLE_CONTRIBUTORS_LIBRARY_GITHUB_TOKEN) || !bundle.containsKey(Contributors.BUNDLE_REPOSITORY_URL)) {
        finish();
    }

    //set the theme
    boolean customTheme = false;
    Contributors.ActivityStyle activityStyle = Contributors.ActivityStyle.DARK;

    if (bundle != null) {
        token = bundle.getString(Contributors.BUNDLE_CONTRIBUTORS_LIBRARY_GITHUB_TOKEN);
        repositoryUrl = bundle.getString(Contributors.BUNDLE_REPOSITORY_URL);
        int themeId = bundle.getInt(Contributors.BUNDLE_THEME, -1);
        if (themeId != -1) {
            customTheme = true;
            setTheme(themeId);
        }

        String style = bundle.getString(Contributors.BUNDLE_STYLE);
        if (style != null) {
            activityStyle = Contributors.ActivityStyle.valueOf(style);
        }
    }

    if (!customTheme) {
        if (activityStyle == Contributors.ActivityStyle.DARK) {
            setTheme(R.style.ContributorsLibraryTheme);
        } else if (activityStyle == Contributors.ActivityStyle.LIGHT) {
            setTheme(R.style.ContributorsLibraryTheme_Light);
        } else if (activityStyle == Contributors.ActivityStyle.LIGHT_DARK_TOOLBAR) {
            setTheme(R.style.ContributorsLibraryTheme_Light_DarkToolbar);
        }
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_github_contributors);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //if we have a darkToolbar set the text white
    if (activityStyle == Contributors.ActivityStyle.LIGHT_DARK_TOOLBAR) {
        toolbar.setTitleTextColor(Color.WHITE);
        toolbar.setSubtitleTextColor(Color.WHITE);
    }
    setSupportActionBar(toolbar);
    //if we use the DarkToolbar style we have to handle the back arrow on our own too
    if (activityStyle == Contributors.ActivityStyle.LIGHT_DARK_TOOLBAR && getSupportActionBar() != null) {
        final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        if (upArrow != null) {
            upArrow.setColorFilter(getResources().getColor(android.R.color.white), PorterDuff.Mode.SRC_ATOP);
        }
        getSupportActionBar().setHomeAsUpIndicator(upArrow);
    }

    String title = getString(R.string.contributors_library_name);
    if (bundle != null && bundle.containsKey(Contributors.BUNDLE_TITLE)) {
        title = bundle.getString(Contributors.BUNDLE_TITLE);
    }

    ActionBar ab = getSupportActionBar();
    if (ab != null) {

        // SetUp ActionBar
        ab.setDisplayHomeAsUpEnabled(true);
        if (TextUtils.isEmpty(title)) {
            ab.setDisplayShowTitleEnabled(false);
        } else {
            ab.setDisplayShowTitleEnabled(true);
            ab.setTitle(title);
        }
    }

    ContributorsFragment fragment = ContributorsFragment.newInstance(token, repositoryUrl);

    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
}
 
Example 11
Source File: ToolbarColorizeHelper.java    From Slide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Use this method to colorize toolbar icons to the desired target color
 *
 * @param toolbarView       toolbar view being colored
 * @param toolbarIconsColor the target color of toolbar icons
 * @param activity          reference to activity needed to register observers
 */
public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, Activity activity) {
    final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY);

    for (int i = 0; i < toolbarView.getChildCount(); i++) {
        final View v = toolbarView.getChildAt(i);

        //Step 1 : Changing the color of back button (or open drawer button).
        if (v instanceof ImageButton) {
            //Action Bar back button
            ((ImageButton) v).getDrawable().setColorFilter(colorFilter);
        }


        if (v instanceof ActionMenuView) {
            for (int j = 0; j < ((ActionMenuView) v).getChildCount(); j++) {

                //Step 2: Changing the color of any ActionMenuViews - icons that are not back button, nor text, nor overflow menu icon.
                //Colorize the ActionViews -> all icons that are NOT: back button | overflow menu
                final View innerView = ((ActionMenuView) v).getChildAt(j);
                if (innerView instanceof ActionMenuItemView) {
                    for (int k = 0; k < ((ActionMenuItemView) innerView).getCompoundDrawables().length; k++) {
                        if (((ActionMenuItemView) innerView).getCompoundDrawables()[k] != null) {
                            final int finalK = k;

                            //Important to set the color filter in seperate thread, by adding it to the message queue
                            //Won't work otherwise.
                            innerView.post(new Runnable() {
                                @Override
                                public void run() {
                                    ((ActionMenuItemView) innerView).getCompoundDrawables()[finalK].setColorFilter(colorFilter);
                                }
                            });
                        }
                    }
                }
            }
        }

        //Step 3: Changing the color of title and subtitle.
        toolbarView.setTitleTextColor(toolbarIconsColor);
        toolbarView.setSubtitleTextColor(toolbarIconsColor);

        //Step 4: Changing the color of the Overflow Menu icon.
        setOverflowButtonColor(activity, colorFilter);
    }
}