Android Open Source - MaterialNavigationDrawer Material Subheader






From Project

Back to project page MaterialNavigationDrawer.

License

The source code is released under:

Apache License

If you think the Android project MaterialNavigationDrawer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package it.neokree.materialnavigationdrawer.elements;
/*from w  w w.ja  v a2  s  . c  o  m*/
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.graphics.Typeface;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import it.neokree.materialnavigationdrawer.R;
import it.neokree.materialnavigationdrawer.util.Utils;

/**
 * Created by neokree on 17/01/15.
 */
public class MaterialSubheader {

    private CharSequence title;
    private int titleColor;

    private TextView text;
    private View view;

    public MaterialSubheader(Context ctx) {
        float density = ctx.getResources().getDisplayMetrics().density;

        // create layout
        LinearLayout layout = new LinearLayout(ctx);
        layout.setOrientation(LinearLayout.VERTICAL);

        // inflate the line
        View view = new View(ctx);
        view.setBackgroundColor(Color.parseColor("#e0e0e0"));
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,1);
        params.setMargins(0,(int) (8 * density), 0 , (int) (8 * density));
        layout.addView(view,params);

        // inflate the text
        text = new TextView(ctx);
        Utils.setAlpha(text,0.54f);
        text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14);
        text.setGravity(Gravity.START);
        LinearLayout.LayoutParams paramsText = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        paramsText.setMargins((int) (16 * density),0, (int) (16 * density) , (int) (4 * density));

        layout.addView(text,paramsText);
        this.view = layout;

        // get attributes from current theme
        Resources.Theme theme = ctx.getTheme();
        TypedValue typedValue = new TypedValue();
        theme.resolveAttribute(R.attr.sectionStyle,typedValue,true);
        TypedArray values = theme.obtainStyledAttributes(typedValue.resourceId,R.styleable.MaterialSection);
        try {
            titleColor = values.getColor(R.styleable.MaterialSubheader_subheaderTitleColor,0x000);


        }
        finally {
            values.recycle();
        }

        // set attributes to the view
        text.setTextColor(Color.BLACK);

    }

    public void setTitleFont(Typeface font) {
        text.setTypeface(font);
    }

    public void setTitle(CharSequence title) {
        this.title = title;
        text.setText(title);
    }

    public void setTitleColor(int color) {
        titleColor = color;
        text.setTextColor(color);
    }

    public int getTitleColor() {
        return titleColor;
    }

    public CharSequence getTitle() {
        return title;
    }

    public View getView() {
        return view;
    }

}




Java Source Code List

it.neokree.example.MainActivity.java
it.neokree.example.backpattern.BackAnywhere.java
it.neokree.example.backpattern.BackPatternCustom.java
it.neokree.example.backpattern.BackToFirst.java
it.neokree.example.dark.Accounts.java
it.neokree.example.dark.CustomDrawerHeader.java
it.neokree.example.dark.ImageDrawerHeader.java
it.neokree.example.dark.MockedAccount.java
it.neokree.example.dark.NoDrawerHeader.java
it.neokree.example.functionalities.CustomAccountSection.java
it.neokree.example.functionalities.KitkatStatusBar.java
it.neokree.example.functionalities.MultiPane.java
it.neokree.example.functionalities.RealColorSections.java
it.neokree.example.functionalities.RippleBackport.java
it.neokree.example.functionalities.UniqueToolbarColor.java
it.neokree.example.functionalities.master_child.ChildFragment.java
it.neokree.example.functionalities.master_child.MasterChildActivity.java
it.neokree.example.functionalities.master_child.MasterFragment.java
it.neokree.example.light.Accounts.java
it.neokree.example.light.CustomDrawerHeader.java
it.neokree.example.light.ImageDrawerHeader.java
it.neokree.example.light.MockedAccount.java
it.neokree.example.light.NoDrawerHeader.java
it.neokree.example.mockedActivity.Profile.java
it.neokree.example.mockedActivity.Settings.java
it.neokree.example.mockedFragments.FragmentButton.java
it.neokree.example.mockedFragments.FragmentIndex.java
it.neokree.example.mockedFragments.FragmentList.java
it.neokree.materialnavigationdrawer.MaterialNavigationDrawer.java
it.neokree.materialnavigationdrawer.elements.MaterialAccount.java
it.neokree.materialnavigationdrawer.elements.MaterialSection.java
it.neokree.materialnavigationdrawer.elements.MaterialSubheader.java
it.neokree.materialnavigationdrawer.elements.listeners.MaterialAccountListener.java
it.neokree.materialnavigationdrawer.elements.listeners.MaterialSectionListener.java
it.neokree.materialnavigationdrawer.util.MaterialActionBarDrawerToggle.java
it.neokree.materialnavigationdrawer.util.MaterialDrawerLayout.java
it.neokree.materialnavigationdrawer.util.TypefaceManager.java
it.neokree.materialnavigationdrawer.util.Utils.java