List of usage examples for android.widget TextView setLayoutParams
public void setLayoutParams(ViewGroup.LayoutParams params)
From source file:com.mydatingapp.ui.base.SkBaseInnerActivity.java
public void setActionBarLogoCounter(int count) { ImageView logo = (ImageView) findViewById(android.R.id.home); if (count < 1) { currentLogoCounter = 0;// ww w . j a v a 2 s .co m logo.setVisibility(View.GONE); return; } else { logo.setVisibility(View.VISIBLE); } currentLogoCounter = count; TextView v = new TextView(getApp()); v.setText(new Integer(count).toString()); v.setBackgroundResource(R.drawable.sidebar_menu_counterbg); v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); v.setDrawingCacheEnabled(true); v.setTextColor(Color.WHITE); v.setPadding(SKDimensions.convertDpToPixel(6, getApp()), 0, SKDimensions.convertDpToPixel(6, getApp()), 0); ActionBar.LayoutParams paramsExample = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, 1); paramsExample.setMargins(0, 0, 0, 0); v.setHeight(SKDimensions.convertDpToPixel(20, getApp())); v.setLayoutParams(paramsExample); // this is the important code :) // Without it the view will have a dimension of 0,0 and the bitmap will be null v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.buildDrawingCache(true); Bitmap b = Bitmap.createBitmap(v.getDrawingCache()); v.setDrawingCacheEnabled(false); logo.setImageDrawable(new BitmapDrawable(getApp().getResources(), b)); logo.setPadding(SKDimensions.convertDpToPixel(3, getApp()), 0, 0, 0); }
From source file:com.moviematch.views.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./* ww w. ja v a 2s . c o m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); textView.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); return textView; }
From source file:com.oubeichen.weather.common.view.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from ww w . ja v a2s. c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT, 1)); return textView; }
From source file:com.cheikh.lazywaimai.widget.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./*from ww w. j av a2s .c o m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); return textView; }
From source file:com.photon.phresco.nativeapp.eshop.activity.ProductDetailActivity.java
/** * Create the details sections at the bottom of the screen dynamically * * @param details// w w w .j a v a2 s . co m * @throws NumberFormatException */ private void renderProdcutDetails(Map<String, String> details) { try { LinearLayout tl = (LinearLayout) findViewById(R.id.product_details_layout); int totalDetails = details.size(); int cnt = 1; PhrescoLogger.info(TAG + "renderProdcutDetails() - totalDetails : " + totalDetails); TextView lblDetailLabel = null; for (Entry<String, String> entry : details.entrySet()) { // Create a TextView to hold the label for product detail lblDetailLabel = new TextView(this); if (cnt == 1) { lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_top); } else if (cnt == totalDetails) { lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_bottom); } else { lblDetailLabel.setBackgroundResource(R.drawable.view_cart_item_middle); } lblDetailLabel.setText(entry.getKey() + ": " + entry.getValue()); lblDetailLabel.setGravity(Gravity.CENTER); lblDetailLabel.setTypeface(Typeface.DEFAULT, style.TextViewStyle); lblDetailLabel.setTextColor(Color.WHITE); lblDetailLabel.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f)); tl.addView(lblDetailLabel); cnt++; } } catch (Exception ex) { PhrescoLogger.info(TAG + "renderProdcutDetails - Exception : " + ex.toString()); PhrescoLogger.warning(ex); } }
From source file:com.hawk.lib.base.ui.widget.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}./*from www . j a va2 s . co m*/ */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(false); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); return textView; }
From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (getShowsDialog()) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); }/* w ww. j a v a 2 s.co m*/ View view = inflater.inflate(R.layout.radial_time_picker_dialog, container, false); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener); Resources res = getResources(); TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId, R.styleable.BetterPickersDialogs); // Prepare some colors to use. int headerBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpBlue)); int bodyBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpBodyBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); int buttonBgColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsBackgroundColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); int buttonTextColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpButtonsTextColor, ContextCompat.getColor(getActivity(), R.color.bpBlue)); mSelectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderSelectedTextColor, ContextCompat.getColor(getActivity(), R.color.bpWhite)); mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersDialogs_bpHeaderUnselectedTextColor, ContextCompat.getColor(getActivity(), R.color.radial_gray_light)); mHourPickerDescription = res.getString(R.string.hour_picker_description); mSelectHours = res.getString(R.string.select_hours); mMinutePickerDescription = res.getString(R.string.minute_picker_description); mSelectMinutes = res.getString(R.string.select_minutes); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mHapticFeedbackController = new HapticFeedbackController(getActivity()); mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), mHapticFeedbackController, mInitialHourOfDay, mInitialMinute, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); tryVibrate(); } }); mTitleTextView = (TextView) view.findViewById(R.id.time_picker_header); if (mTitleText != null) { mTitleTextView.setVisibility(View.VISIBLE); mTitleTextView.setText(mTitleText); } else { mTitleTextView.setVisibility(View.GONE); } mError = (NumberPickerErrorTextView) view.findViewById(R.id.error); if (hasTimeLimits()) { mError.setVisibility(View.INVISIBLE); } else { mError.setVisibility(View.GONE); } mDoneButton = (Button) view.findViewById(R.id.done_button); if (mDoneText != null) { mDoneButton.setText(mDoneText); } mDoneButton.setTextColor(buttonTextColor); mDoneButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { tryVibrate(); } doneClickValidateAndCallback(); } }); mDoneButton.setOnKeyListener(keyboardListener); Button cancelButton = (Button) view.findViewById(R.id.cancel_button); if (mCancelText != null) { cancelButton.setText(mCancelText); } cancelButton.setTextColor(buttonTextColor); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { tryVibrate(); dismiss(); } }); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); } else { mAmPmTextView.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } updateAmPmDisplay(amOrPm); mTimePicker.setAmOrPm(amOrPm); } }); } mAllowAutoAdvance = true; setHour(mInitialHourOfDay, true); setMinute(mInitialMinute); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<Integer>(); } // Set the theme at the end so that the initialize()s above don't counteract the theme. mTimePicker.setTheme(themeColors); // Set the colors for each view based on the theme. view.findViewById(R.id.time_display_background).setBackgroundColor(headerBgColor); view.findViewById(R.id.ok_cancel_buttons_layout).setBackgroundColor(buttonBgColor); view.findViewById(R.id.time_display).setBackgroundColor(headerBgColor); view.findViewById(R.id.time_picker_error_holder).setBackgroundColor(headerBgColor); ((TextView) view.findViewById(R.id.separator)).setTextColor(mUnselectedColor); ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mUnselectedColor); mTimePicker.setBackgroundColor(bodyBgColor); return view; }
From source file:com.sdspikes.fireworks.FireworksActivity.java
private TextView makeNewCardTextView(int width, GameState.Card card) { width = Math.min(width, MAX_CARD_WIDTH); width = Math.max(width, MIN_CARD_WIDTH); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT); TextView textView = new TextView(this); textView.setLayoutParams(params); textView.setGravity(Gravity.CENTER); textView.setText(String.valueOf(card.rank)); textView.setBackgroundResource(HandFragment.cardColorToBGColor.get(card.color)); textView.setTextColor(getResources().getColor(HandFragment.cardColorToTextColor(card.color))); return textView; }
From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java
private void displayArtistInfo_bk(JSONObject j) throws JSONException { if (imageLoader == null) imageLoader = ImageLoader.getInstance(); if (!imageLoader.isInited()) imageLoader.init(config);/* w ww . ja v a2 s.c o m*/ Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString()); JSONObject j_artist_info = j.getJSONObject("artist"); tArtistName.setText(j_artist_info.getString("name")); final JSONObject urls = j_artist_info.optJSONObject("urls"); final JSONArray videos = j_artist_info.optJSONArray("video"); final JSONArray images = j_artist_info.optJSONArray("images"); final String fm_image = j.optString("fm_image"); final JSONArray available_images = new JSONArray(); ArrayList<String> image_urls = new ArrayList<String>(); if (fm_image != null) { image_urls.add(fm_image); } Log.i("musicInfo", images.toString()); if (images != null) { for (int i = 0; i < images.length(); i++) { JSONObject image = images.getJSONObject(i); int width = image.optInt("width", 0); int height = image.optInt("height", 0); String url = image.optString("url", ""); Log.i("musicInfo", i + ": " + url); if ((width * height > 10000) && (width * height < 100000) && (!url.contains("userserve-ak"))) { //if ((width>300&&width<100)&&(height>300&&height<1000)&&(!url.contains("userserve-ak"))) { image_urls.add(url); Log.i("musicInfo", "Selected: " + url); //available_images.put(image); } } int random = (int) (Math.random() * image_urls.size()); final String f_url = image_urls.get(random); //int random = (int) (Math.random() * available_images.length()); //final JSONObject fImage = available_images.length()>0?available_images.getJSONObject(random > images.length() ? 0 : random):images.getJSONObject(0); Log.i("musicInfo", "Total image#=" + available_images.length() + " Selected image#=" + random + " " + f_url); imageLoader.displayImage(f_url, ArtistImage, new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { lLinkList.removeAllViews(); //String attr = fImage.optJSONObject("license").optString("attribution"); //tAttribution.setText("Credit. " + ((attr == null) || (attr.contains("n/a")) ? "Unknown" : attr)); if (urls != null) { String[] jsonName = { "wikipedia_url", "mb_url", "lastfm_url", "official_url", "twitter_url" }; for (int i = 0; i < jsonName.length; i++) { if ((urls.optString(jsonName[i]) != null) && (urls.optString(jsonName[i]) != "")) { Log.d("musicinfo", "Link URL: " + urls.optString(jsonName[i])); TextView tv = new TextView(getApplicationContext()); tv.setTextSize(11); tv.setPadding(16, 16, 16, 16); tv.setTextColor(Color.LTGRAY); tv.setTypeface(Typeface.SANS_SERIF); tv.setGravity(Gravity.CENTER_VERTICAL); tv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); switch (jsonName[i]) { case "official_url": tv.setText("HOME."); break; case "wikipedia_url": tv.setText("WIKI."); break; case "mb_url": tv.setText("Music Brainz."); break; case "lastfm_url": tv.setText("Last FM."); break; case "twitter_url": tv.setText("Twitter."); break; } try { tv.setTag(urls.getString(jsonName[i])); } catch (JSONException e) { e.printStackTrace(); } tv.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setData(Uri.parse((String) v.getTag())); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); Toast.makeText(getApplicationContext(), "Open the Link...", Toast.LENGTH_SHORT).show(); //finish(); } }); lLinkList.addView(tv); } } } else { TextView tv = new TextView(getApplicationContext()); tv.setTextSize(11); tv.setPadding(16, 16, 16, 16); tv.setTextColor(Color.LTGRAY); tv.setTypeface(Typeface.SANS_SERIF); tv.setGravity(Gravity.CENTER_VERTICAL); tv.setText("Sorry, No Link Here..."); lLinkList.addView(tv); } if (videos != null) { jVideoArray = videos; mAdapter = new StaggeredViewAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, generateImageData(videos)); //if (mData == null) { mData = generateImageData(videos); //} //mAdapter.clear(); for (JSONObject data : mData) { mAdapter.add(data); } mGridView.setAdapter(mAdapter); } else { } adjBottomColor(((ImageView) view).getDrawable()); } @Override public void onLoadingCancelled(String imageUri, View view) { } }); } }
From source file:com.peoit.twopointcf.ui.view.SlidingTabLayout.SlidingTabLayout.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int)}.//from w ww.j a v a 2 s . co m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); //textView.setTextSize(TAB_VIEW_TEXT_SIZE_SP); textView.setTypeface(Typeface.DEFAULT_BOLD); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style textView.setAllCaps(true); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding / 2, 0, padding / 2, 0); //textView.setGravity(Gravity.CENTER); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT)); return textView; }