List of usage examples for android.content.res TypedArray getResourceId
@AnyRes public int getResourceId(@StyleableRes int index, int defValue)
From source file:android.support.designox.widget.TabLayout.java
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Add the TabStrip mTabStrip = new SlidingTabStrip(context); super.addView(mTabStrip, 0, new HorizontalScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, R.style.Widget_Design_TabLayout); mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0)); mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0); mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart); mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop); mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd); mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom); mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, R.style.TextAppearance_Design_Tab); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance); try {//from ww w .j a va 2 s . c o m mTabTextSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); mTabTextColors = ta.getColorStateList(R.styleable.TextAppearance_android_textColor); } finally { ta.recycle(); } if (a.hasValue(R.styleable.TabLayout_tabTextColor)) { // If we have an explicit text color set, use it instead mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor); } if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) { // We have an explicit selected text color set, so we need to make merge it with the // current colors. This is exposed so that developers can use theme attributes to set // this (theme attrs in ColorStateLists are Lollipop+) final int selected = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0); mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected); } mRequestedTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, INVALID_WIDTH); mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, INVALID_WIDTH); mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0); mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0); mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED); mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL); a.recycle(); // TODO add attr for these final Resources res = getResources(); mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line); mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width); // Now apply the tab mode and gravity applyModeAndGravity(); }
From source file:com.gm.grecyclerview.GmRecyclerView.java
private void initAttrs(Context context, AttributeSet attrs, int defStyle) { TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.grv_GRecyclerView, defStyle, 0);/*w ww . ja v a 2 s .c o m*/ layoutMode = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_layoutMode, 0); gridSpanCount = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_gridSpanCount, 0); gridSpanSequence = typedArray.getString(R.styleable.grv_GRecyclerView_grv_gridSpanSequence); spacing = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_spacing, 0); verticalSpacing = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_verticalSpacing, 0); horizontalSpacing = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_horizontalSpacing, 0); isSpacingIncludeEdge = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_isSpacingIncludeEdge, false); showDivider = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_showDivider, false); showLastDivider = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_showLastDivider, false); dividerColor = typedArray.getColor(R.styleable.grv_GRecyclerView_grv_dividerColor, 0); dividerOrientation = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_dividerOrientation, 2); dividerPaddingLeft = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingLeft, 0); dividerPaddingRight = typedArray .getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingRight, 0); dividerPaddingTop = typedArray.getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingTop, 0); dividerPaddingBottom = typedArray .getDimensionPixelSize(R.styleable.grv_GRecyclerView_grv_dividerPaddingBottom, 0); isSnappyEnabled = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_snappy, false); snapAlignment = typedArray.getInt(R.styleable.grv_GRecyclerView_grv_snap_alignment, 0); showEmptyStateView = typedArray.getBoolean(R.styleable.grv_GRecyclerView_grv_showEmptyStateView, false); emptyStateViewRes = typedArray.getResourceId(R.styleable.grv_GRecyclerView_grv_emptyStateView, 0); loadMoreViewRes = typedArray.getResourceId(R.styleable.grv_GRecyclerView_grv_loadMoreView, 0); typedArray.recycle(); }
From source file:chao.widget.tablayout.TabLayout.java
@SuppressLint("PrivateResource") public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); checkAppCompatTheme(context);// w w w . j av a 2s . c o m // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Add the TabStrip mTabStrip = new SlidingTabStrip(context); super.addView(mTabStrip, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, Widget_Design_TabLayout); mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(TabLayout_tabIndicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(TabLayout_tabIndicatorColor, 0)); mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a .getDimensionPixelSize(TabLayout_tabPadding, 0); mTabPaddingStart = a.getDimensionPixelSize(TabLayout_tabPaddingStart, mTabPaddingStart); mTabPaddingTop = a.getDimensionPixelSize(TabLayout_tabPaddingTop, mTabPaddingTop); mTabPaddingEnd = a.getDimensionPixelSize(TabLayout_tabPaddingEnd, mTabPaddingEnd); mTabPaddingBottom = a.getDimensionPixelSize(TabLayout_tabPaddingBottom, mTabPaddingBottom); mTabTextAppearance = a.getResourceId(TabLayout_tabTextAppearance, TextAppearance_Design_Tab); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance); try { mTabTextSize = ta.getDimensionPixelSize(TextAppearance_android_textSize, 0); mTabTextColors = ta.getColorStateList(TextAppearance_android_textColor); } finally { ta.recycle(); } if (a.hasValue(TabLayout_tabTextColor)) { // If we have an explicit text color set, use it instead mTabTextColors = a.getColorStateList(TabLayout_tabTextColor); } if (a.hasValue(TabLayout_tabSelectedTextColor)) { // We have an explicit selected text color set, so we need to make merge it with the // current colors. This is exposed so that developers can use theme attributes to set // this (theme attrs in ColorStateLists are Lollipop+) final int selected = a.getColor(TabLayout_tabSelectedTextColor, 0); mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected); } mRequestedTabMinWidth = a.getDimensionPixelSize(TabLayout_tabMinWidth, INVALID_WIDTH); mRequestedTabMaxWidth = a.getDimensionPixelSize(TabLayout_tabMaxWidth, INVALID_WIDTH); mTabBackgroundResId = a.getResourceId(TabLayout_tabBackground, 0); mContentInsetStart = a.getDimensionPixelSize(TabLayout_tabContentStart, 0); mMode = a.getInt(TabLayout_tabMode, MODE_FIXED_COMMON); mTabGravity = a.getInt(TabLayout_tabGravity, GRAVITY_FILL); a.recycle(); a = context.obtainStyledAttributes(attrs, chao.widget.tablayout.R.styleable.TabLayout); mTabTextSize = a.getDimensionPixelSize(chao.widget.tablayout.R.styleable.TabLayout_tabTextSize, dpToPx(12)); mTabSelectedTextSize = a.getDimensionPixelSize( chao.widget.tablayout.R.styleable.TabLayout_tabSelectedTextSize, (int) mTabTextSize); mTabTextStyle = a.getInt(chao.widget.tablayout.R.styleable.TabLayout_tabTextStyle, 0); mTabSelectedTextStyle = a.getInt(chao.widget.tablayout.R.styleable.TabLayout_tabSelectedTextStyle, 0); a.recycle(); // TODO add attr for these final Resources res = getResources(); mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line); // mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width); mScrollableTabMinWidth = 0; // Now apply the tab mode and gravity applyModeAndGravity(); if (mMode != MODE_SCROLLABLE) { setOverScrollMode(HorizontalScrollView.OVER_SCROLL_NEVER); } }
From source file:com.android.purenexussettings.TinkerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tinker); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);/* www . ja va 2 s . co m*/ // set up some defaults boolean cLockInstalled; FRAG_ARRAY_START = getResources().getIntArray(R.array.nav_drawer_cat_nums)[0]; mTitle = mDrawerTitle = getTitle(); mPackageName = getPackageName(); LAST_SLIDE_BAR_TAB = 0; mBackPress = false; mIgnoreBack = false; mFromClick = false; mMenu = false; fullyClosed = true; openingHalf = true; // for backstack tracking fragmentStack = new Stack<>(); // check if cLock installed try { PackageInfo pi = getPackageManager().getPackageInfo(KEY_LOCK_CLOCK_PACKAGE_NAME, 0); cLockInstalled = pi.applicationInfo.enabled; } catch (PackageManager.NameNotFoundException e) { cLockInstalled = false; } // load slide menu items - titles and frag names navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items); navMenuFrags = getResources().getStringArray(R.array.nav_drawer_fragments); // nav drawer icons from resources TypedArray navMenuIcons = getResources().obtainTypedArray(R.array.nav_drawer_icons); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mNavView = (NavigationView) findViewById(R.id.slidermenu); // create navigationview items Menu menu = mNavView.getMenu(); // pulled in crap menu in xml, need to clear it first menu.clear(); // pull in category names and numbers in each String[] navMenuCats = getResources().getStringArray(R.array.nav_drawer_cats); int[] navMenuCatCounts = getResources().getIntArray(R.array.nav_drawer_cat_nums); // set up some counters int j = 0; int total = 0; SubMenu submenu = null; // go through the total possible menu list for (int i = 0; i < navMenuTitles.length; i++) { // when the count equals a threshold value, increment/sum and add submenu if (i == (total + navMenuCatCounts[j])) { total += navMenuCatCounts[j]; // format submenu headings SpannableString strcat = new SpannableString(navMenuCats[j]); strcat.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0, strcat.length(), 0); strcat.setSpan(new RelativeSizeSpan(0.85f), 0, strcat.length(), 0); strcat.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, strcat.length(), 0); // is the 10 * (j + 1) bit needed...? Maybe not... meh submenu = menu.addSubMenu((j + 1), 10 * (j + 1), 10 * (j + 1), strcat); j++; } // assuming all are skipped before first submenu, only add menu items if total <> 0 if (total > 0) { // format menu item title SpannableString stritem = new SpannableString(navMenuTitles[i]); stritem.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.alphawhite)), 0, stritem.length(), 0); // group id is j, i is item id and order..., then title - includes logic for conditional entries if (cLockInstalled || !(navMenuTitles[i].equals("cLock"))) { // an attempt to add icon if included... if (navMenuIcons.getResourceId(i, -1) != -1) { submenu.add(j, i, i, stritem).setIcon(navMenuIcons.getResourceId(i, -1)); } else { submenu.add(j, i, i, stritem); } } } } // remove icon tint from NavView mNavView.setItemIconTintList(null); mNavView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem item) { // check for external app launching navdrawer items if (navMenuTitles[item.getItemId()].equals("cLock")) { mIgnore = true; mDrawerLayout.closeDrawer(mNavView); launchcLock(); } // if nothing was caught in the above, do the usual prep to show frag stuff if (!mIgnore) { mItemPosition = item.getItemId(); mFromClick = true; setTitle(navMenuTitles[mItemPosition]); removeCurrent(); mDrawerLayout.closeDrawer(mNavView); } return true; } }); // Recycle the typed array navMenuIcons.recycle(); // enabling action bar app icon and behaving it as toggle button getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, //nav menu toggle icon R.string.app_name, // nav drawer open - description for accessibility R.string.app_name // nav drawer close - description for accessibility ) { @Override public void onDrawerClosed(View view) { mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED, mNavView); getSupportActionBar().setTitle(mTitle); // calling onPrepareOptionsMenu() to show action bar icons openingHalf = true; invalidateOptionsMenu(); // now that the drawer animation is done - load fragment if (mIgnore || !mFromClick) { mIgnore = false; } else { displayView(mItemPosition); } } @Override public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(mDrawerTitle); // calling onPrepareOptionsMenu() to hide action bar icons openingHalf = false; invalidateOptionsMenu(); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, slideOffset); fullyClosed = (slideOffset == 0.0f); if (slideOffset < 0.5f && !openingHalf) { openingHalf = true; invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } else if (slideOffset > 0.5f && openingHalf) { openingHalf = false; invalidateOptionsMenu(); // calls onPrepareOptionsMenu() } } }; mDrawerLayout.setDrawerListener(mDrawerToggle); fragmentManager = getFragmentManager(); if (savedInstanceState == null) { // on first time display view for first nav item displayView(mItemPosition = getIntent().getIntExtra(EXTRA_START_FRAGMENT, 0)); } }
From source file:com.commonsware.cwac.crossport.design.widget.TabLayoutLite.java
public TabLayoutLite(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // ThemeUtils.checkAppCompatTheme(context); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Add the TabStrip mTabStrip = new SlidingTabStrip(context); super.addView(mTabStrip, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, R.style.Widget_Design_TabLayout); mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0)); mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0); mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart); mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop); mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd); mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom); mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, R.style.TextAppearance_Design_Tab); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance); try {/* w w w. j av a2 s .com*/ mTabTextSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); mTabTextColors = ta.getColorStateList(R.styleable.TextAppearance_android_textColor); } finally { ta.recycle(); } if (a.hasValue(R.styleable.TabLayout_tabTextColor)) { // If we have an explicit text color set, use it instead mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor); } if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) { // We have an explicit selected text color set, so we need to make merge it with the // current colors. This is exposed so that developers can use theme attributes to set // this (theme attrs in ColorStateLists are Lollipop+) final int selected = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0); mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected); } mRequestedTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, INVALID_WIDTH); mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, INVALID_WIDTH); mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0); mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0); mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED); mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL); a.recycle(); // TODO add attr for these final Resources res = getResources(); mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line); mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width); // Now apply the tab mode and gravity applyModeAndGravity(); }
From source file:com.commonsware.cwac.crossport.design.widget.TabLayout.java
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // ThemeUtils.checkAppCompatTheme(context); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Add the TabStrip mTabStrip = new SlidingTabStrip(context); super.addView(mTabStrip, 0, new HorizontalScrollView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, R.style.Widget_Design_TabLayout); mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0)); mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0); mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart); mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop); mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd); mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom); mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, R.style.TextAppearance_Design_Tab); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, R.styleable.TextAppearance); try {/* ww w. jav a 2 s. c o m*/ mTabTextSize = ta.getDimensionPixelSize(R.styleable.TextAppearance_android_textSize, 0); mTabTextColors = ta.getColorStateList(R.styleable.TextAppearance_android_textColor); } finally { ta.recycle(); } if (a.hasValue(R.styleable.TabLayout_tabTextColor)) { // If we have an explicit text color set, use it instead mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor); } if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) { // We have an explicit selected text color set, so we need to make merge it with the // current colors. This is exposed so that developers can use theme attributes to set // this (theme attrs in ColorStateLists are Lollipop+) final int selected = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0); mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected); } mRequestedTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, INVALID_WIDTH); mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, INVALID_WIDTH); mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0); mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0); mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED); mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL); a.recycle(); // TODO add attr for these final Resources res = getResources(); mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line); mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width); // Now apply the tab mode and gravity applyModeAndGravity(); }
From source file:com.jecelyin.android.common.widget.TabLayout.java
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Set us to fill the View port setFillViewport(true);/*from w w w.j a v a 2 s . c o m*/ // Add the TabStrip mTabStrip = new SlidingTabStrip(context); TypedArray a; //add divider support if (Build.VERSION.SDK_INT >= 11) { a = context.getTheme().obtainStyledAttributes(attrs, new int[] { android.R.attr.divider, android.R.attr.showDividers, android.R.attr.dividerPadding, }, defStyleAttr, 0); mDivider = a.getDrawable(0); mShowDividers = a.getInt(1, LinearLayout.SHOW_DIVIDER_NONE); mDividerPadding = a.getDimensionPixelSize(2, 0); a.recycle(); //????? a = context.getTheme().obtainStyledAttributes(attrs, new int[] { android.R.attr.lineSpacingMultiplier }, defStyleAttr, 0); mSpacingMult = a.getFloat(0, 1.0f); a.recycle(); if (Build.VERSION.SDK_INT >= 14) { mTabStrip.setDividerPadding(mDividerPadding); } else { Rect b = mDivider.getBounds(); mDivider.setBounds(b.left, b.top, b.right + mDividerPadding * 2, b.bottom); } mTabStrip.setDividerDrawable(mDivider); mTabStrip.setShowDividers(mShowDividers); } //end addView(mTabStrip, LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, R.style.Widget_Design_TabLayout); mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0)); mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, R.style.TextAppearance_Design_Tab); mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0); mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart); mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop); mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd); mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom); if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) { mTabSelectedTextColor = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0); mTabSelectedTextColorSet = true; } mTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, 0); mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, 0); mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0); mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0); mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED); mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL); a.recycle(); // Now apply the tab mode and gravity applyModeAndGravity(); }
From source file:android.support.design.widget.TabLayout.java
public TabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); ThemeUtils.checkAppCompatTheme(context); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Add the TabStrip mTabStrip = new SlidingTabStrip(context); super.addView(mTabStrip, 0, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabLayout, defStyleAttr, R.style.Widget_Design_TabLayout); mTabStrip.setSelectedIndicatorHeight(a.getDimensionPixelSize(R.styleable.TabLayout_tabIndicatorHeight, 0)); mTabStrip.setSelectedIndicatorColor(a.getColor(R.styleable.TabLayout_tabIndicatorColor, 0)); mTabPaddingStart = mTabPaddingTop = mTabPaddingEnd = mTabPaddingBottom = a .getDimensionPixelSize(R.styleable.TabLayout_tabPadding, 0); mTabPaddingStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingStart, mTabPaddingStart); mTabPaddingTop = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingTop, mTabPaddingTop); mTabPaddingEnd = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingEnd, mTabPaddingEnd); mTabPaddingBottom = a.getDimensionPixelSize(R.styleable.TabLayout_tabPaddingBottom, mTabPaddingBottom); mTabTextAppearance = a.getResourceId(R.styleable.TabLayout_tabTextAppearance, R.style.TextAppearance_Design_Tab); // Text colors/sizes come from the text appearance first final TypedArray ta = context.obtainStyledAttributes(mTabTextAppearance, android.support.v7.appcompat.R.styleable.TextAppearance); try {// w w w. j av a 2s .c om mTabTextSize = ta.getDimensionPixelSize( android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize, 0); mTabTextColors = ta .getColorStateList(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor); } finally { ta.recycle(); } if (a.hasValue(R.styleable.TabLayout_tabTextColor)) { // If we have an explicit text color set, use it instead mTabTextColors = a.getColorStateList(R.styleable.TabLayout_tabTextColor); } if (a.hasValue(R.styleable.TabLayout_tabSelectedTextColor)) { // We have an explicit selected text color set, so we need to make merge it with the // current colors. This is exposed so that developers can use theme attributes to set // this (theme attrs in ColorStateLists are Lollipop+) final int selected = a.getColor(R.styleable.TabLayout_tabSelectedTextColor, 0); mTabTextColors = createColorStateList(mTabTextColors.getDefaultColor(), selected); } mRequestedTabMinWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMinWidth, INVALID_WIDTH); mRequestedTabMaxWidth = a.getDimensionPixelSize(R.styleable.TabLayout_tabMaxWidth, INVALID_WIDTH); mTabBackgroundResId = a.getResourceId(R.styleable.TabLayout_tabBackground, 0); mContentInsetStart = a.getDimensionPixelSize(R.styleable.TabLayout_tabContentStart, 0); mMode = a.getInt(R.styleable.TabLayout_tabMode, MODE_FIXED); mTabGravity = a.getInt(R.styleable.TabLayout_tabGravity, GRAVITY_FILL); a.recycle(); // TODO add attr for these final Resources res = getResources(); mTabTextMultiLineSize = res.getDimensionPixelSize(R.dimen.design_tab_text_size_2line); mScrollableTabMinWidth = res.getDimensionPixelSize(R.dimen.design_tab_scrollable_min_width); // Now apply the tab mode and gravity applyModeAndGravity(); }
From source file:com.csform.android.uiapptemplate.view.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/* w w w. j a va 2 s . co m*/ setWillNotDraw(false); mTabsContainer = new LinearLayout(context); mTabsContainer.setOrientation(LinearLayout.HORIZONTAL); addView(mTabsContainer); mRectPaint = new Paint(); mRectPaint.setAntiAlias(true); mRectPaint.setStyle(Style.FILL); DisplayMetrics dm = getResources().getDisplayMetrics(); mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm); mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm); mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm); mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm); mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm); mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm); mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm); mDividerPaint = new Paint(); mDividerPaint.setAntiAlias(true); mDividerPaint.setStrokeWidth(mDividerWidth); // get system attrs for container TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS); int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.black)); mUnderlineColor = textPrimaryColor; mDividerColor = textPrimaryColor; mIndicatorColor = textPrimaryColor; int padding = a.getDimensionPixelSize(PADDING_INDEX, 0); mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0); mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0); a.recycle(); String tabTextTypefaceName = "sans-serif"; // Use Roboto Medium as the default typeface from API 21 onwards if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { tabTextTypefaceName = "sans-serif-medium"; mTabTextTypefaceStyle = Typeface.NORMAL; } // get custom attrs for tabs and container a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor); mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, mIndicatorHeight); mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor); mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, mUnderlineHeight); mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor); mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth); mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, mDividerPadding); isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs); mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset); isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle); mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, mTabPadding); mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, mTabBackgroundResId); mTabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabTextSize, mTabTextSize); mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor) ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor) : null; mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle); isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps); int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA); String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily); a.recycle(); //Tab text color selector if (mTabTextColor == null) { mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha, Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor))); } //Tab text typeface and style if (fontFamily != null) { tabTextTypefaceName = fontFamily; } mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle); //Bottom padding for the tabs container parent view to show indicator and underline setTabsContainerParentViewPaddings(); //Configure tab's container LayoutParams for either equal divided space or just wrap tabs mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); }
From source file:com.ecomnationmobile.library.Control.PagerSlidingTabStrip.java
public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setFillViewport(true);/*from ww w .j av a 2s. c o m*/ setWillNotDraw(false); mTabsContainer = new LinearLayout(context); mTabsContainer.setOrientation(LinearLayout.HORIZONTAL); addView(mTabsContainer); mRectPaint = new Paint(); mRectPaint.setAntiAlias(true); mRectPaint.setStyle(Style.FILL); DisplayMetrics dm = getResources().getDisplayMetrics(); mScrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mScrollOffset, dm); mIndicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mIndicatorHeight, dm); mUnderlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mUnderlineHeight, dm); mDividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerPadding, dm); mTabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mTabPadding, dm); mDividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, mDividerWidth, dm); mTabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mTabTextSize, dm); mDividerPaint = new Paint(); mDividerPaint.setAntiAlias(true); mDividerPaint.setStrokeWidth(mDividerWidth); // get system attrs for container TypedArray a = context.obtainStyledAttributes(attrs, ANDROID_ATTRS); int textPrimaryColor = a.getColor(TEXT_COLOR_PRIMARY, getResources().getColor(android.R.color.white)); mUnderlineColor = textPrimaryColor; mDividerColor = textPrimaryColor; mIndicatorColor = textPrimaryColor; int padding = a.getDimensionPixelSize(PADDING_INDEX, 0); mPaddingLeft = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_LEFT_INDEX, 0); mPaddingRight = padding > 0 ? padding : a.getDimensionPixelSize(PADDING_RIGHT_INDEX, 0); a.recycle(); String tabTextTypefaceName = "sans-serif"; // Use Roboto Medium as the default typeface from API 21 onwards if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { tabTextTypefaceName = "sans-serif-medium"; mTabTextTypefaceStyle = Typeface.NORMAL; } // get custom attrs for tabs and container a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip); mIndicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, mIndicatorColor); mIndicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight, mIndicatorHeight); mUnderlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, mUnderlineColor); mUnderlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight, mUnderlineHeight); mDividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, mDividerColor); mDividerWidth = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerWidth, mDividerWidth); mDividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding, mDividerPadding); isExpandTabs = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, isExpandTabs); mScrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, mScrollOffset); isPaddingMiddle = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsPaddingMiddle, isPaddingMiddle); mTabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, mTabPadding); mTabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground, mTabBackgroundResId); mTabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabTextSize, mTabTextSize); mTabTextColor = a.hasValue(R.styleable.PagerSlidingTabStrip_pstsTabTextColor) ? a.getColorStateList(R.styleable.PagerSlidingTabStrip_pstsTabTextColor) : null; mTabTextTypefaceStyle = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextStyle, mTabTextTypefaceStyle); isTabTextAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTabTextAllCaps, isTabTextAllCaps); int tabTextAlpha = a.getInt(R.styleable.PagerSlidingTabStrip_pstsTabTextAlpha, DEF_VALUE_TAB_TEXT_ALPHA); String fontFamily = a.getString(R.styleable.PagerSlidingTabStrip_pstsTabTextFontFamily); a.recycle(); //Tab text color white_selector if (mTabTextColor == null) { mTabTextColor = createColorStateList(textPrimaryColor, textPrimaryColor, Color.argb(tabTextAlpha, Color.red(textPrimaryColor), Color.green(textPrimaryColor), Color.blue(textPrimaryColor))); } //Tab text typeface and style if (fontFamily != null) { tabTextTypefaceName = fontFamily; } mTabTextTypeface = Typeface.create(tabTextTypefaceName, mTabTextTypefaceStyle); //Bottom padding for the tabs container parent view to show indicator and underline setTabsContainerParentViewPaddings(); //Configure tab's container LayoutParams for either equal divided space or just wrap tabs mTabLayoutParams = isExpandTabs ? new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f) : new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); }