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

The following examples show how to use android.support.v7.widget.Toolbar#setBackgroundColor() . 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 MLManager with GNU General Public License v3.0 6 votes vote down vote up
private void setInitialConfiguration() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null) {
        getSupportActionBar().setTitle(R.string.app_name);
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(UtilsUI.darker(appPreferences.getPrimaryColorPref(), 0.8));
        toolbar.setBackgroundColor(appPreferences.getPrimaryColorPref());
        if (!appPreferences.getNavigationBlackPref()) {
            getWindow().setNavigationBarColor(appPreferences.getPrimaryColorPref());
        }
    }
}
 
Example 2
Source File: SettingsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
@Override
public void onThemeApplied(Theme theme) {
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(toolbarColor);
    toolbar.setTitleTextColor(textColorPrimary);

    if (theme.darkStatusBarIcons() &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int statusBarColor = getStatusBarColor();
        getWindow().setStatusBarColor(statusBarColor);
    }
}
 
Example 3
Source File: MainActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
@Override
public void onThemeApplied(Theme theme) {
    if (pick_photos) {
        return;
    }

    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(toolbarColor);
    toolbar.setTitleTextColor(textColorPrimary);

    if (theme.darkStatusBarIcons()) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    } else {
        Util.setLightStatusBarIcons(findViewById(R.id.root_view));
    }

    if (theme.statusBarOverlay()) {
        addStatusBarOverlay(toolbar);
    }
}
 
Example 4
Source File: VirtualAlbumsActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
@Override
public void onThemeApplied(Theme theme) {
    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(toolbarColor);
    toolbar.setTitleTextColor(textColorPrimary);

    if (theme.darkStatusBarIcons() &&
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        int statusBarColor = getStatusBarColor();
        getWindow().setStatusBarColor(statusBarColor);
    }
}
 
Example 5
Source File: MainActivity.java    From miappstore with Apache License 2.0 6 votes vote down vote up
@Override
protected void initToolBar() {
    super.initToolBar();
    view = View.inflate(this, R.layout.activity_main, null);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
    toolbar.setBackgroundColor(getResources().getColor(R.color.light_toolbar));
    toolbar.setTitle("应用商店");
    toolbar.setLogo(R.mipmap.logo);//设置Logo
    setSupportActionBar(toolbar);
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.app_name, R.string.app_name
    );
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}
 
Example 6
Source File: WendaContentFragment.java    From Toutiao with Apache License 2.0 6 votes vote down vote up
@Override
protected void initView(View view) {
    super.initView(view);
    Toolbar toolbar = view.findViewById(R.id.toolbar);
    initToolBar(toolbar, true, getString(R.string.title_wenda));
    toolbar.setOnClickListener(view1 -> recyclerView.smoothScrollToPosition(0));
    toolbar.setBackgroundColor(SettingUtil.getInstance().getColor());

    adapter = new MultiTypeAdapter(oldItems);
    Register.registerWendaContentItem(adapter);
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (canLoadMore) {
                canLoadMore = false;
                presenter.doLoadMoreData();
            }
        }
    });
    setHasOptionsMenu(true);
}
 
Example 7
Source File: AboutActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if(Utils.hasKitKat() && !Utils.hasLollipop()){
		setTheme(R.style.Theme_Document_Translucent);
	}
	setContentView(R.layout.activity_about);

	Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
	mToolbar.setTitleTextAppearance(this, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
	if(Utils.hasKitKat() && !Utils.hasLollipop()) {
		//((LinearLayout.LayoutParams) mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
		mToolbar.setPadding(0, getStatusBarHeight(this), 0, 0);
	}
	int color = SettingsActivity.getPrimaryColor();
	mToolbar.setBackgroundColor(color);
	setSupportActionBar(mToolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setTitle(null);
	setUpDefaultStatusBar();

	initControls();
}
 
Example 8
Source File: AboutActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	if(Utils.hasKitKat() && !Utils.hasLollipop()){
		setTheme(R.style.Theme_Document_Translucent);
	}
	setContentView(R.layout.activity_about);

	Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
	mToolbar.setTitleTextAppearance(this, R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);
	if(Utils.hasKitKat() && !Utils.hasLollipop()) {
		//((LinearLayout.LayoutParams) mToolbar.getLayoutParams()).setMargins(0, getStatusBarHeight(this), 0, 0);
		mToolbar.setPadding(0, getStatusBarHeight(this), 0, 0);
	}
	int color = SettingsActivity.getPrimaryColor();
	mToolbar.setBackgroundColor(color);
	setSupportActionBar(mToolbar);
	getSupportActionBar().setDisplayHomeAsUpEnabled(true);
	getSupportActionBar().setTitle(null);
	setUpDefaultStatusBar();

	initControls();
}
 
Example 9
Source File: ViewUtils.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
/**
 * Update the Toolbar background color and title.
 * @param activity
 * @param toolbar
 * @param alpha
 * @param title
 * @param color
 */
public static void updateToolbarBackground(Activity activity, Toolbar toolbar,
                                           int alpha, String title, int color) {
    if (defaultTitleTextColor == -1) {
        int[] textColorAttr = new int[]{R.attr.actionMenuTextColor};
        TypedValue typedValue = new TypedValue();
        int indexOfAttrTextColor = 0;
        TypedArray a = activity.obtainStyledAttributes(typedValue.data, textColorAttr);
        defaultTitleTextColor = a.getColor(indexOfAttrTextColor, -1);
        a.recycle();
    }
    toolbar.setTitle(title);
    toolbar.setTitleTextColor(adjustAlpha(defaultTitleTextColor, alpha));
    int toolbarColor = adjustAlpha(color, alpha);
    if (MizLib.hasJellyBean()) {
        int topColor = darkenColor(color, alpha / 255f);
        topColor = adjustAlpha(topColor, Math.max(125, alpha));
        int[] colors = {topColor, toolbarColor};
        toolbar.setBackground(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors));
    } else {
        toolbar.setBackgroundColor(toolbarColor);
    }
}
 
Example 10
Source File: AppActivity.java    From MLManager with GNU General Public License v3.0 6 votes vote down vote up
private void setInitialConfiguration() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != null ) {
        getSupportActionBar().setTitle("");
        getSupportActionBar().setHomeButtonEnabled(true);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        getWindow().setStatusBarColor(UtilsUI.darker(appPreferences.getPrimaryColorPref(), 0.8));
        toolbar.setBackgroundColor(appPreferences.getPrimaryColorPref());
        if (!appPreferences.getNavigationBlackPref()) {
            getWindow().setNavigationBarColor(appPreferences.getPrimaryColorPref());
        }
    }
}
 
Example 11
Source File: StorageActivity.java    From openapk with GNU General Public License v3.0 6 votes vote down vote up
private void setInitialConfiguration() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });
    toolbar.setBackgroundColor(AppPreferences.get(this).getPrimaryColor());

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(R.string.storage);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    getWindow().setStatusBarColor(OtherUtils.dark(AppPreferences.get(this).getPrimaryColor(), 0.8));
    getWindow().setNavigationBarColor(AppPreferences.get(this).getPrimaryColor());
}
 
Example 12
Source File: PickerActivity.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo_picker);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(Define.ACTIONBAR_COLOR);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        uiUtil.setStatusBarColor(this);
    }
    ActionBar bar = getSupportActionBar();
    if (bar != null) bar.setDisplayHomeAsUpEnabled(true);

    a = (Album) getIntent().getSerializableExtra("album");
    GridLayoutManager gridLayoutManager = new GridLayoutManager(this, Define.PHOTO_SPAN_COUNT, GridLayoutManager.VERTICAL, false);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    recyclerView.setLayoutManager(gridLayoutManager);
    pickedImageBeans = new ArrayList<>();

    pickerController = new PickerController(this, getSupportActionBar(), recyclerView, a.bucketname);

    ArrayList<String> path = getIntent().getStringArrayListExtra(Define.INTENT_PATH);
    if (path != null) {
        for (int i = 0; i < path.size(); i++) {
            pickedImageBeans.add(new PickedImageBean(i + 1, path.get(i), -1));
        }
    }
    pickerController.setActionbarTitle(pickedImageBeans.size());

    permissionCheck = new PermissionCheck(this);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (permissionCheck.CheckStoragePermission())
            new DisplayImage().execute();
    } else
        new DisplayImage().execute();

}
 
Example 13
Source File: GalleryActivity.java    From HeartBeat with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery);

    long eventId = getIntent().getLongExtra(EVENT_ID, -1);
    String path = "";
    if (eventId == -1) {
        path = getIntent().getStringExtra(PATH);
    }

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(Color.BLACK);
    toolbar.setTitle("");
    toolbar.setAlpha(0.6f);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mImage = (PhotoView) findViewById(R.id.imageview);

    mImage.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
        @Override
        public void onPhotoTap(View view, float x, float y) {
            finish();
        }
    });

    if (eventId != -1) {
        String imagePath = ImageUtils.getImageByEventId(this, eventId).getPath();
        Glide.with(this).load(GalleryUtils.getImagePath(imagePath)).into(mImage);
    } else {
        Glide.with(this).load(GalleryUtils.getImagePath(path)).into(mImage);
    }
}
 
Example 14
Source File: BaseActivity.java    From Cook-It-Android-XML-Template with MIT License 5 votes vote down vote up
public void setupToolbar(int toolbarId, String title, @ColorRes int titleColor, @ColorRes int colorBg, @DrawableRes int burger){
    toolbar = (Toolbar) findViewById(toolbarId);
    toolbar.setBackgroundColor(getResources().getColor(colorBg));
    setSupportActionBar(toolbar);
    TextView pageTitle = (TextView) toolbar.findViewById(R.id.tv_title);
    pageTitle.setText(title);
    pageTitle.setTextColor(getResources().getColor(titleColor));
    getSupportActionBar().setTitle("");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeAsUpIndicator(burger);
}
 
Example 15
Source File: AbsBaseActivity.java    From LLApp with Apache License 2.0 5 votes vote down vote up
private void initToolBar() {
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setBackgroundColor(StaticValue.color);
    if (toolbar != null) {
        setSupportActionBar(toolbar);
        abTitle = (TextView) toolbar.findViewById(R.id.toolbar_title);
    }
    if (abTitle != null) {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayShowTitleEnabled(false);
        }
    }
}
 
Example 16
Source File: MoreInfoActivity.java    From openlauncher with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_more);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(_appSettings.getPrimaryColor());

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    SettingsAboutFragment settingsAboutFragment = SettingsAboutFragment.newInstance();
    transaction.replace(R.id.fragment_holder, settingsAboutFragment, SettingsAboutFragment.TAG).commit();
}
 
Example 17
Source File: MaterialMainActivity.java    From MaterialPreference with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    if (MaterialPrefUtil.isDarkThemeEnable())
        setTheme(R.style.AppThemeDark);
    else
        setTheme(R.style.AppThemeLight);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    mToolbar = (Toolbar) findViewById(R.id.materialpref_toolbar);

    mToolbar.setTitle(mToolbarTitle);
    mToolbar.setBackgroundColor(Color.parseColor(MaterialPrefUtil.primaryColor[MaterialPrefUtil.getPrimaryColorPosition()]));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.parseColor(MaterialPrefUtil.primaryColorDark[MaterialPrefUtil.getPrimaryColorPosition()]));
    }

    setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    getSupportFragmentManager().beginTransaction()
            .replace(R.id.materialpref_bodylayout, new MaterialPreferenceFragment())
            .commit();
}
 
Example 18
Source File: DataChartActivity.java    From Memory-capsule with Apache License 2.0 5 votes vote down vote up
private void initToolbar(){
    Toolbar toolbar_chart=(Toolbar) this.findViewById(R.id.toolbar_chart);
    toolbar_chart.setBackgroundColor(integer0);
    setSupportActionBar(toolbar_chart);
    getSupportActionBar().setHomeButtonEnabled(true);//设置返回键可用
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("数据分析");
    toolbar_chart.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            finish();
        }
    });
}
 
Example 19
Source File: MainWindow.java    From FancyPlaces with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.clear();

    getMenuInflater().inflate(curState.curMenu, menu);

    Toolbar toolbar = (Toolbar) findViewById(R.id.main_window_toolbar);
    if (curState.curMenu == R.menu.menu_main_window_multi_select) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setTitle(getString(R.string.main_multi_selection_title));
        toolbar.setBackgroundColor(getResources().getColor(R.color.ColorPrimaryDark));
        int noOfChild = toolbar.getChildCount();
        View view;

        // animate toolbar elements
        for (int i = 1; i < noOfChild; i++) {
            view = toolbar.getChildAt(i);
            view.setAlpha(0);
            view.setScaleY(0);
            view.setPivotY((float) 0.5 * view.getHeight());
            view.animate().setDuration(200).scaleY(1).alpha(1);
        }

    } else if (curState.curMenu == R.menu.menu_main_window) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        setDefaultTitle();
        toolbar.setBackgroundColor(getResources().getColor(R.color.ColorPrimary));
    }

    return super.onPrepareOptionsMenu(menu);
}
 
Example 20
Source File: AlbumActivity.java    From Camera-Roll-Android-App with Apache License 2.0 4 votes vote down vote up
@Override
public void onSelectorModeEnter() {
    final Toolbar toolbar = findViewById(R.id.toolbar);
    toolbar.setActivated(true);
    toolbar.animate().translationY(0.0f).start();

    if (theme.darkStatusBarIconsInSelectorMode()) {
        Util.setDarkStatusBarIcons(findViewById(R.id.root_view));
    } else {
        Util.setLightStatusBarIcons(findViewById(R.id.root_view));
    }

    if (!pick_photos) {
        ColorFade.fadeBackgroundColor(toolbar, toolbarColor, accentColor);

        ColorFade.fadeToolbarTitleColor(toolbar, accentTextColor, null);

        //fade overflow menu icon
        ColorFade.fadeDrawableColor(toolbar.getOverflowIcon(), textColorSecondary, accentTextColor);

        Drawable selectAll = menu.findItem(R.id.select_all).getIcon();
        selectAll.setAlpha(0);
        ColorFade.fadeDrawableAlpha(selectAll, 255);

        ColorDrawable statusBarOverlay = getStatusBarOverlay();
        if (statusBarOverlay != null) {
            ColorFade.fadeDrawableAlpha(statusBarOverlay, 0);
        }

        Drawable navIcon = toolbar.getNavigationIcon();
        if (navIcon instanceof Animatable) {
            ((Animatable) navIcon).start();
            ColorFade.fadeDrawableColor(navIcon, textColorSecondary, accentTextColor);
        }
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Drawable d;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    AnimatedVectorDrawable drawable = (AnimatedVectorDrawable)
                            ContextCompat.getDrawable(AlbumActivity.this,
                                    R.drawable.cancel_to_back_avd);
                    //mutating avd to reset it
                    drawable.mutate();
                    d = drawable;
                } else {
                    d = ContextCompat.getDrawable(AlbumActivity.this,
                            R.drawable.ic_clear_white);
                }
                d = DrawableCompat.wrap(d);
                DrawableCompat.setTint(d.mutate(), accentTextColor);
                toolbar.setNavigationIcon(d);
            }
        }, navIcon instanceof Animatable ? (int) (500 * Util.getAnimatorSpeed(this)) : 0);
    } else {
        toolbar.setBackgroundColor(accentColor);
        toolbar.setTitleTextColor(accentTextColor);
    }

    handleMenuVisibilityForSelectorMode(true);

    if (!pick_photos) {
        animateFab(true, false);
    }
}