List of usage examples for android.view View setContentDescription
@RemotableViewMethod public void setContentDescription(CharSequence contentDescription)
From source file:com.dimelo.sampleapp.google.IconSlidingTabLayout.java
@Override protected void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final View.OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TextView tabTitleView = null;/*from w w w. j a v a 2s . c o m*/ ImageView iconImageView = null; if (mTabViewLayoutId == 0) { setCustomTabView(R.layout.icon_sliding_tab, R.id.tab_layout_title); } // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(R.layout.icon_sliding_tab, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); tabTitleView.setBackgroundResource(outValue.resourceId); tabTitleView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); tabTitleView.setPadding(padding, padding, padding, padding); iconImageView = (ImageView) tabView.findViewById(R.id.tab_layout_icon); // if (tabView == null) { // tabView = createDefaultTabView(getContext()); // } // // if (tabTitleView == null && TextView.class.isInstance(tabView)) { // tabTitleView = (TextView) tabView; // } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabTitleView.setText(adapter.getPageTitle(i)); // Not very beautifull, can be improved in the future if (adapter instanceof ViewPagerIconAndTextAdapter) { // int id = ((ViewPagerIconAndTextAdapter)adapter).getPageIconId(i); // Drawable drawable = getContext().getResources().getDrawable(id); // DrawableCompat.setTint(drawable, Color.GREEN); // iconImageView.setImageDrawable(drawable); updateIcon(iconImageView, i); } tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } tabTitleView.setTextColor(getResources().getColorStateList(R.color.text_slider_selector)); } }
From source file:br.edu.ifpb.breath.slidingtabs.SlidingTabLayout.java
private void populateTabStrip() { final PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null; TextView tabTitleView = null;//ww w . j a v a 2 s .c o m ImageView tabIconView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); tabIconView = (ImageView) tabView.findViewById(mTabViewImageViewId); } if (tabView == null && !mUseIcons) { tabView = createDefaultTabView(getContext(), 0); tabView.setAlpha(i == 0 ? 1.0f : 0.25f); } if (tabView == null && mUseIcons) { tabView = createDefaultTabView(getContext(), 1); tabView.setAlpha(i == 0 ? 1.0f : 0.25f); } if (tabTitleView == null && TextView.class.isInstance(tabView)) { tabTitleView = (TextView) tabView; tabTitleView.setAlpha(i == 0 ? 1.0f : 0.25f); } if (tabIconView == null && ImageView.class.isInstance(tabView)) { tabIconView = (ImageView) tabView; tabIconView.setAlpha(i == 0 ? 1.0f : 0.25f); } if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } if (mUseIcons) { tabIconView.setVisibility(View.VISIBLE); if (tabTitleView != null) tabTitleView.setVisibility(View.GONE); if (mIcons.containsKey(i)) tabIconView.setImageDrawable(mIcons.get(i)); } else { tabTitleView.setVisibility(View.VISIBLE); if (tabIconView != null) tabIconView.setVisibility(View.GONE); tabTitleView.setText(adapter.getPageTitle(i)); tabTitleView.setTextColor(mTextColor); } tabView.setOnClickListener(tabClickListener); String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } mTabStrip.addView(tabView); if (i == mViewPager.getCurrentItem()) { tabView.setSelected(true); } } }
From source file:com.guerinet.materialtabs.TabLayout.java
/** * Adds the tabs based on a list of Strings to use as tab titles * * @param listener The {@link TabClickListener} to use when a tab is clicked * @param initialTab The initial tab to show * @param titles The titles for the tabs */// w ww .j a v a2 s . c o m private void addTabs(TabClickListener listener, int initialTab, List<String> titles) { //Clear any existing tabs clear(); //Reset the current position mCurrentPosition = -1; View initialTabView = null; //Go through the titles for (int i = 0; i < titles.size(); i++) { View tabView; TextView tabTitleView = null; //If there is a custom tab view layout id set, try and inflate it if (mTabViewLayoutId != 0) { tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false); //Set the default selector if we should use the default selector if (mDefaultSelector) { tabView.setBackgroundResource(getTabBackground()); } tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId); prepareTextView(tabTitleView); //Set up the icon if needed if (mTabViewIconId != null) { ImageView iconView = (ImageView) tabView.findViewById(mTabViewIconId); //Wrap through the icons iconView.setImageResource(mIconIds[i % mIconIds.length]); } } else { //If not, just use the default tab view tabView = createDefaultTabView(); } //If there is no tab title and the tab view is a TextView, use that if (tabTitleView == null) { if (!TextView.class.isInstance(tabView)) { //If there is no tab title, throw an exception throw new IllegalStateException("Could not find the title TextView"); } tabTitleView = (TextView) tabView; } //Set equal weights if we are to distribute these tabs evenly if (mDistributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } //Set the text and the listener tabTitleView.setText(titles.get(i)); tabView.setOnClickListener(listener); //Set the content description if there is one String desc = mContentDescriptions.get(i, null); if (desc != null) { tabView.setContentDescription(desc); } //Add it to the strip mTabStrip.addView(tabView); //If we found the initial tab, store it if (i == initialTab) { initialTabView = tabView; } } //Click on the first tab if there is one. This will set the initial position if (initialTabView != null) { initialTabView.performClick(); } }