List of usage examples for android.widget TextView getLayoutParams
@ViewDebug.ExportedProperty(deepExport = true, prefix = "layout_") public ViewGroup.LayoutParams getLayoutParams()
From source file:android.support.v17.leanback.app.ErrorSupportFragment.java
private static void setTopMargin(TextView textView, int topMargin) { ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) textView.getLayoutParams(); lp.topMargin = topMargin;/*from www . j a va 2s .c o m*/ textView.setLayoutParams(lp); }
From source file:com.ofalvai.bpinfo.util.UiUtils.java
/** * Adds a rectangular icon for the affected route. * * First it creates a TextView, then sets the style properties of the view. * The custom colored rounded background is achieved by a Drawable and a ColorFilter on top of that. *///from w w w.jav a 2s . c o m public static void addRouteIcon(Context context, @NonNull ViewGroup root, @NonNull Route route) { ContextThemeWrapper iconContextTheme = new ContextThemeWrapper(context, R.style.RouteIcon); TextView iconView = new TextView(iconContextTheme); iconView.setText(route.getShortName()); iconView.setTextColor(route.getTextColor()); iconView.setContentDescription(Utils.getContentDescriptionForRoute(context, route)); root.addView(iconView); // Layout attributes defined in R.style.RouteIcon were ignored before attaching the view to // a parent, so we need to manually set them ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) iconView.getLayoutParams(); params.width = ViewGroup.LayoutParams.WRAP_CONTENT; int margin = (int) context.getResources().getDimension(R.dimen.route_icon_margin); params.rightMargin = margin; params.topMargin = margin; // A requestLayout() call is not necessary here because the setBackground() method below // will call that anyway. //iconView.requestLayout(); // Setting a custom colored rounded background drawable as background Drawable iconBackground = context.getResources().getDrawable(R.drawable.rounded_corner_5dp); if (iconBackground != null) { ColorFilter colorFilter = new LightingColorFilter(Color.rgb(1, 1, 1), route.getColor()); iconBackground.mutate().setColorFilter(colorFilter); iconView.setBackground(iconBackground); } }
From source file:MainActivity.java
public void goAnimate(View view) { ViewGroup root = (ViewGroup) findViewById(R.id.layout); Scene scene = new Scene(root); Transition transition = new ChangeBounds(); TransitionManager.beginDelayedTransition(root, transition); TextView textViewTop = (TextView) findViewById(R.id.textViewTop); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textViewTop.getLayoutParams(); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1); params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0); textViewTop.setLayoutParams(params); TextView textViewBottom = (TextView) findViewById(R.id.textViewBottom); params = (RelativeLayout.LayoutParams) textViewBottom.getLayoutParams(); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); params.addRule(RelativeLayout.ALIGN_PARENT_TOP, 1); textViewBottom.setLayoutParams(params); TransitionManager.go(scene);/*from ww w.ja va 2s. co m*/ }
From source file:com.learnncode.tabsample.BaseActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_base); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); mTabHost.setup(this, getSupportFragmentManager(), android.R.id.tabcontent); mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator(getResources().getString(R.string.tab_one)), TabOneFrgment.class, null); mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.tab_two)), TabTwoFrgment.class, null); mTabHost.setCurrentTabByTag("tag2"); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { TextView textView = (TextView) mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) textView .getLayoutParams();/* w w w . ja va 2s . c om*/ params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title).setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) textView .getLayoutParams(); params.gravity = Gravity.CENTER; mTabHost.getTabWidget().getChildAt(i).findViewById(android.R.id.title).setLayoutParams(params); } } mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); TabOneFrgment tabOneFrgment = (TabOneFrgment) fragmentManager.findFragmentByTag("tab1"); TabTwoFrgment tabTwoFrgment = (TabTwoFrgment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { if (tabOneFrgment != null) { if (tabTwoFrgment != null) { fragmentTransaction.hide(tabTwoFrgment); } fragmentTransaction.show(tabOneFrgment); } } else { if (tabTwoFrgment != null) { if (tabOneFrgment != null) { fragmentTransaction.hide(tabOneFrgment); } fragmentTransaction.show(tabTwoFrgment); } } fragmentTransaction.commit(); } }); }
From source file:org.orange.querysystem.content.TabsAdapter.java
private void setTabForIfLowerThanHONEYCOMB() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { View child = mTabHost.getTabWidget().getChildAt(getCount() - 1); child.setBackgroundColor(0xFFB5E61D); TextView tv = (TextView) child.findViewById(android.R.id.title); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tv.getLayoutParams(); params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0); //?? params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); //? params.setMargins(dp2px(10), dp2px(4), dp2px(10), dp2px(4)); child.getLayoutParams().height = RelativeLayout.LayoutParams.WRAP_CONTENT; }//from w w w. j av a 2s. c om }
From source file:csms19.inapp.msg.customgallery.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override//w ww .ja v a 2s.c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_home_customgallery); String name = getIntent().getStringExtra("username"); mediasellistnr = this; chooserheadertext = (TextView) findViewById(R.id.chooserheadertext); chooserhbackbtnlay = (RelativeLayout) findViewById(R.id.chooserhbackbtnlay); if (name != null) chooserheadertext.setText(name); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); chooserhbackbtnlay.setOnClickListener(clickListener); mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent); if (MediaChooserConstants.showVideo) { mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Videos" + " "), BucketVideoFragment.class, null); } // ///////Images set right tab so write below if (MediaChooserConstants.showImage) { mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Images" + " "), BucketImageFragment.class, null); } // mTabHost.getTabWidget().setBackgroundColor( // getResources().getColor(R.color.tabs_color)); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { View childView = mTabHost.getTabWidget().getChildAt(i); TextView textView = (TextView) childView.findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) textView .getLayoutParams(); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; textView.setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) textView .getLayoutParams(); params.gravity = Gravity.CENTER; textView.setLayoutParams(params); } textView.setTextColor(getResources().getColor(R.color.black)); textView.setTextSize(convertDipToPixels(10)); } ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1"); BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { if (imageFragment == null) { BucketImageFragment newImageFragment = new BucketImageFragment(); fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1"); } else { if (videoFragment != null) { fragmentTransaction.hide(videoFragment); } fragmentTransaction.show(imageFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); } else { if (videoFragment == null) { final BucketVideoFragment newVideoFragment = new BucketVideoFragment(); fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2"); } else { if (imageFragment != null) { fragmentTransaction.hide(imageFragment); } fragmentTransaction.show(videoFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.BLACK); } fragmentTransaction.commit(); } }); }
From source file:info.tellmetime.DaydreamService.java
@Override public void onAttachedToWindow() { super.onAttachedToWindow(); setInteractive(true);/*from ww w. ja v a2 s . co m*/ setFullscreen(true); setContentView(R.layout.daydream); LinearLayout mClock = (LinearLayout) findViewById(R.id.clock); SharedPreferences settings = getSharedPreferences("PREFS", Context.MODE_PRIVATE); mHighlightColor = settings.getInt(TellmetimeActivity.HIGHLIGHT, Color.WHITE); mBacklightColor = settings.getInt(TellmetimeActivity.BACKLIGHT, getResources().getColor(R.color.backlight_light)); mMinutesSize = settings.getInt(TellmetimeActivity.MINUTES_SIZE, 36); isNightMode = settings.getBoolean(TellmetimeActivity.NIGHTMODE, false); setScreenBright(!isNightMode); findViewById(R.id.overlay).setBackgroundColor( getResources().getColor(isNightMode ? R.color.night_mode_overlay : android.R.color.transparent)); RelativeLayout mSurface = (RelativeLayout) findViewById(R.id.surface); mSurface.setBackgroundColor( settings.getInt(TellmetimeActivity.BACKGROUND, getResources().getColor(R.color.background))); switch (settings.getInt(TellmetimeActivity.BACKGROUND_MODE, TellmetimeActivity.MODE_BACKGROUND_SOLID)) { case TellmetimeActivity.MODE_BACKGROUND_WALLPAPER: ((ImageView) findViewById(R.id.background_image)) .setImageDrawable(WallpaperManager.getInstance(this).getDrawable()); break; case TellmetimeActivity.MODE_BACKGROUND_IMAGE: try { ((ImageView) findViewById(R.id.background_image)).setImageBitmap(BitmapFactory.decodeStream( new FileInputStream(new File(getFilesDir(), TellmetimeActivity.IMAGE_FILE_NAME)))); } catch (Exception ignored) { // Image is not set, set background color loaded from setting is visible. } break; } mShorterEdge = Math.min(getResources().getDisplayMetrics().widthPixels, getResources().getDisplayMetrics().heightPixels); mDensity = getResources().getDisplayMetrics().density; RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.CENTER_IN_PARENT); lp.width = mShorterEdge; mClock.setLayoutParams(lp); Typeface mTypeface = Typeface.createFromAsset(getAssets(), "Roboto-BoldCondensed.ttf"); final float mItemSize = mShorterEdge / mClock.getChildCount(); final int mRowMargin = (int) -(mItemSize / 2.2); for (int i = 0; i < mClock.getChildCount(); i++) { LinearLayout row = (LinearLayout) mClock.getChildAt(i); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams(); params.bottomMargin = mRowMargin; row.setLayoutParams(params); for (int j = 0; j < row.getChildCount(); j++) { TextView tv = (TextView) row.getChildAt(j); tv.setTypeface(mTypeface); tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemSize); tv.setTextColor(mBacklightColor); tv.setShadowLayer(mShorterEdge / 200 * mDensity, 0, 0, mBacklightColor); } } LinearLayout lastRow = (LinearLayout) mClock.getChildAt(mClock.getChildCount() - 1); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) lastRow.getLayoutParams(); params.bottomMargin = 0; lastRow.setLayoutParams(params); TextView twenty = (TextView) findViewById(R.id.twenty); params = (LinearLayout.LayoutParams) twenty.getLayoutParams(); params.leftMargin = 0; twenty.setLayoutParams(params); inflateMinutesIndicators(); }
From source file:com.nicolls.ablum.activity.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override/* w w w .j a va2s.c om*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_home_media_chooser); mediaType = getIntent().getStringExtra("mediaType"); List<String> pathList = getIntent().getStringArrayListExtra("pathList"); headerBarTitle = (TextView) findViewById(R.id.titleTextViewFromMediaChooserHeaderBar); headerBarCamera = (ImageView) findViewById(R.id.cameraImageViewFromMediaChooserHeaderBar); headerBarBack = (ImageView) findViewById(R.id.backArrowImageViewFromMediaChooserHeaderView); headerBarDone = (TextView) findViewById(R.id.doneTextViewViewFromMediaChooserHeaderView); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); headerBarBack.setOnClickListener(clickListener); headerBarCamera.setOnClickListener(clickListener); headerBarDone.setOnClickListener(clickListener); headerBarDone.setVisibility(View.INVISIBLE); mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent); mTabHost.addTab( mTabHost.newTabSpec("tab1").setIndicator(getResources().getString(R.string.images_tab) + " "), BucketImageFragment.class, null); mTabHost.addTab( mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.videos_tab) + " "), BucketVideoFragment.class, null); mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tabs_color)); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { View childView = mTabHost.getTabWidget().getChildAt(i); TextView textView = (TextView) childView.findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams(); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; textView.setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams(); params.gravity = Gravity.CENTER; textView.setLayoutParams(params); } textView.setTextColor(getResources().getColor(R.color.tabs_title_color)); textView.setTextSize(convertDipToPixels(10)); } ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { // Toast.makeText(getApplicationContext(),tabId,Toast.LENGTH_LONG).show(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1"); BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { headerBarTitle.setText(getResources().getString(R.string.image)); headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button); headerBarCamera.setTag(getResources().getString(R.string.image)); if (imageFragment == null) { BucketImageFragment newImageFragment = new BucketImageFragment(); fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1"); } else { if (videoFragment != null) { fragmentTransaction.hide(videoFragment); } fragmentTransaction.show(imageFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); } else { headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.selector_video_button); headerBarCamera.setTag(getResources().getString(R.string.video)); if (videoFragment == null) { final BucketVideoFragment newVideoFragment = new BucketVideoFragment(); fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2"); } else { if (imageFragment != null) { fragmentTransaction.hide(imageFragment); } fragmentTransaction.show(videoFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); } fragmentTransaction.commit(); } }); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) headerBarCamera.getLayoutParams(); params.height = convertDipToPixels(40); params.width = convertDipToPixels(40); headerBarCamera.setLayoutParams(params); headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE); headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15)); if (TextUtils.equals(mediaType, MediaChooserConstants.TYPE_PHOTO)) {//? mTabHost.setCurrentTab(0); headerBarTitle.setText(getResources().getString(R.string.image)); headerBarCamera.setTag(getResources().getString(R.string.image)); headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button); } else { mTabHost.setCurrentTab(1); headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setTag(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.selector_video_button); } }
From source file:com.example.de.taomi2.mediachooser.activity.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override/* w w w . j a va2s .c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_home_media_chooser); headerBarTitle = (TextView) findViewById(R.id.titleTextViewFromMediaChooserHeaderBar); headerBarCamera = (ImageView) findViewById(R.id.cameraImageViewFromMediaChooserHeaderBar); headerBarBack = (ImageView) findViewById(R.id.backArrowImageViewFromMediaChooserHeaderView); headerBarDone = (TextView) findViewById(R.id.doneTextViewViewFromMediaChooserHeaderView); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.ic_video_unselect_from_media_chooser_header_bar); headerBarCamera.setTag(getResources().getString(R.string.video)); headerBarBack.setOnClickListener(clickListener); headerBarCamera.setOnClickListener(clickListener); headerBarDone.setOnClickListener(clickListener); if (!MediaChooserConstants.showCameraVideo) { headerBarCamera.setVisibility(View.GONE); } mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent); if (MediaChooserConstants.showVideo) { mTabHost.addTab( mTabHost.newTabSpec("tab2") .setIndicator(getResources().getString(R.string.videos_tab) + " "), BucketVideoFragment.class, null); } if (MediaChooserConstants.showImage) { mTabHost.addTab( mTabHost.newTabSpec("tab1") .setIndicator(getResources().getString(R.string.images_tab) + " "), BucketImageFragment.class, null); } mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tabs_color)); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { View childView = mTabHost.getTabWidget().getChildAt(i); TextView textView = (TextView) childView.findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams(); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; textView.setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams(); params.gravity = Gravity.CENTER; textView.setLayoutParams(params); } textView.setTextColor(getResources().getColor(R.color.tabs_title_color)); textView.setTextSize(convertDipToPixels(10)); } ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1"); BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { headerBarTitle.setText(getResources().getString(R.string.image)); headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button); headerBarCamera.setTag(getResources().getString(R.string.image)); if (imageFragment == null) { BucketImageFragment newImageFragment = new BucketImageFragment(); fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1"); } else { if (videoFragment != null) { fragmentTransaction.hide(videoFragment); } fragmentTransaction.show(imageFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); } else { headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.selector_video_button); headerBarCamera.setTag(getResources().getString(R.string.video)); if (videoFragment == null) { final BucketVideoFragment newVideoFragment = new BucketVideoFragment(); fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2"); } else { if (imageFragment != null) { fragmentTransaction.hide(imageFragment); } fragmentTransaction.show(videoFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); } fragmentTransaction.commit(); } }); RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) headerBarCamera.getLayoutParams(); params.height = convertDipToPixels(40); params.width = convertDipToPixels(40); headerBarCamera.setLayoutParams(params); headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE); headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15)); }
From source file:com.learnncode.mediachooser.activity.BucketHomeFragmentActivity.java
@SuppressLint("ResourceAsColor") @Override/* w w w . j ava2s . c om*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_home_media_chooser); headerBarTitle = (TextView) findViewById(R.id.titleTextViewFromMediaChooserHeaderBar); headerBarCamera = (ImageView) findViewById(R.id.cameraImageViewFromMediaChooserHeaderBar); headerBarBack = (ImageView) findViewById(R.id.backArrowImageViewFromMediaChooserHeaderView); headerBarDone = (TextView) findViewById(R.id.doneTextViewViewFromMediaChooserHeaderView); mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost); headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.ic_video_unselect_from_media_chooser_header_bar); headerBarCamera.setTag(getResources().getString(R.string.video)); headerBarBack.setOnClickListener(clickListener); headerBarCamera.setOnClickListener(clickListener); headerBarDone.setOnClickListener(clickListener); if (!MediaChooserConstants.showCameraVideo) { headerBarCamera.setVisibility(View.GONE); } mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent); if (MediaChooserConstants.showVideo) { mTabHost.addTab( mTabHost.newTabSpec("tab2") .setIndicator(getResources().getString(R.string.videos_tab) + " "), BucketVideoFragment.class, null); } if (MediaChooserConstants.showImage) { mTabHost.addTab( mTabHost.newTabSpec("tab1") .setIndicator(getResources().getString(R.string.images_tab) + " "), BucketImageFragment.class, null); } mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tabs_color)); for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) { View childView = mTabHost.getTabWidget().getChildAt(i); TextView textView = (TextView) childView.findViewById(android.R.id.title); if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) { RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) textView .getLayoutParams(); params.addRule(RelativeLayout.CENTER_HORIZONTAL); params.addRule(RelativeLayout.CENTER_VERTICAL); params.height = RelativeLayout.LayoutParams.MATCH_PARENT; params.width = RelativeLayout.LayoutParams.WRAP_CONTENT; textView.setLayoutParams(params); } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) { LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) textView .getLayoutParams(); params.gravity = Gravity.CENTER; textView.setLayoutParams(params); } textView.setTextColor(getResources().getColor(R.color.tabs_title_color)); textView.setTextSize(convertDipToPixels(10)); } ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); mTabHost.setOnTabChangedListener(new OnTabChangeListener() { @Override public void onTabChanged(String tabId) { android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1"); BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2"); android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (tabId.equalsIgnoreCase("tab1")) { headerBarTitle.setText(getResources().getString(R.string.image)); headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button); headerBarCamera.setTag(getResources().getString(R.string.image)); if (imageFragment == null) { BucketImageFragment newImageFragment = new BucketImageFragment(); fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1"); } else { if (videoFragment != null) { fragmentTransaction.hide(videoFragment); } fragmentTransaction.show(imageFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); } else { headerBarTitle.setText(getResources().getString(R.string.video)); headerBarCamera.setBackgroundResource(R.drawable.selector_video_button); headerBarCamera.setTag(getResources().getString(R.string.video)); if (videoFragment == null) { final BucketVideoFragment newVideoFragment = new BucketVideoFragment(); fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2"); } else { if (imageFragment != null) { fragmentTransaction.hide(imageFragment); } fragmentTransaction.show(videoFragment); } ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title))) .setTextColor(Color.WHITE); ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title))) .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color)); } fragmentTransaction.commit(); } }); RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) headerBarCamera .getLayoutParams(); params.height = convertDipToPixels(40); params.width = convertDipToPixels(40); headerBarCamera.setLayoutParams(params); headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE); headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15)); }