List of usage examples for android.widget TextView setPadding
@Override public void setPadding(int left, int top, int right, int bottom)
From source file:de.eidottermihi.rpicheck.activity.MainActivity.java
private View createTextView(String text) { final TextView tempText = new TextView(this); tempText.setText(text);//from w w w . j a va 2s. c om float pix = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()); tempText.setPadding((int) (pix), (int) (pix), 0, 0); return tempText; }
From source file:cn.caimatou.canting.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 w w w.j av a 2s .c o m */ protected TextView createDefaultTabView(Context context) { TextView textView = new TextView(context); textView.setGravity(Gravity.CENTER); int textSize = (mTextSize <= 0 ? TAB_VIEW_TEXT_SIZE_SP : mTextSize); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); // TypedValue outValue = new TypedValue(); // getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, // outValue, true); // textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.born2go.lazzybee.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 w w w . ja v a 2s .c om */ 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); textView.setTextColor(getResources().getColor(R.color.white)); // 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 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); return textView; }
From source file:com.studyonthegoapp.slidingtabs.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 w w. j ava2 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); // textView.setLayoutParams(new LinearLayout.LayoutParams( // ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); textView.setLayoutParams( new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.egloos.hyunyi.musicinfo.LinkPopUp.java
private void displayArtistInfo(JSONObject j) throws JSONException { if (imageLoader == null) imageLoader = ImageLoader.getInstance(); if (!imageLoader.isInited()) imageLoader.init(config);/*from www .j a v a 2 s. c om*/ Log.i("musicInfo", "LinkPopUp. displayArtistInfo " + j.toString()); //JSONObject j_artist_info = j.getJSONObject("artist"); final String artist_name = j.getString("name"); tArtistName.setText(artist_name); final JSONObject urls = j.optJSONObject("urls"); final JSONArray videos = j.optJSONArray("video"); final JSONArray images = j.optJSONArray("images"); final String msg = artist_name.replaceAll("\\p{Punct}", " ").replaceAll("\\p{Space}", "+"); AsyncHttpClient client = new AsyncHttpClient(); String fmURL = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=" + msg + "&autocorrect[1]&format=json&api_key=ca4c10f9ae187ebb889b33ba12da7ee9"; Log.i("musicInfo", fmURL); client.get(fmURL, new AsyncHttpResponseHandler() { @Override public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { String r = new String(responseBody); ArrayList<String> image_urls = new ArrayList<String>(); try { Log.i("musicInfo", "Communicating with LastFM..."); JSONObject json = new JSONObject(r); Log.i("musicInfo", json.toString()); json = json.getJSONObject("artist"); Log.i("musicInfo", json.toString()); JSONArray artist_images = json.optJSONArray("image"); Log.i("musicInfo", artist_images.toString()); for (int i = 0; i < artist_images.length(); i++) { JSONObject j = artist_images.getJSONObject(i); Log.i("musicInfo", j.optString("size")); if (j.optString("size").contains("extralarge")) { image_urls.add(j.optString("#text")); //b.putString("fm_image", j.getString("#text")); //Log.i("musicInfo", j.getString("#text")); break; } } } catch (JSONException e) { e.printStackTrace(); } if (images != null) { for (int i = 0; i < images.length(); i++) { JSONObject image = null; try { image = images.getJSONObject(i); } catch (JSONException e) { e.printStackTrace(); } 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); Log.i("musicInfo", "Total image#=" + image_urls.size() + " Selected image#=" + random + " " + f_url); if (image_urls.size() > 0) { 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); 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) { } }); } else { ArtistImage.setImageResource(R.drawable.lamb_no_image_available); } } @Override public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { } }); }
From source file:com.mods.grx.settings.utils.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 a 2 s . 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); //grx I prefer default textsize // textView.setTypeface(Typeface.DEFAULT_BOLD); // grx i do not want bold textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); //textView.setAllCaps(true); //grx, I prefer not capitals textView.setAllCaps(false); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); // grx text colors TypedArray a = getContext().getTheme().obtainStyledAttributes(new int[] { R.attr.tabs_text_color }); ColorStateList color = a.getColorStateList(0); a.recycle(); textView.setTextColor(color); return textView; }
From source file:com.wewe.android.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)}.// w ww.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.setTextColor(getResources().getColor(TAB_VIEW_TEXT_COLOR)); textView.setTypeface(Typeface.DEFAULT_BOLD); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); textView.setPadding(padding, padding, padding, padding); return textView; }
From source file:com.andreadec.musicplayer.MainActivity.java
private void showItemInfo(PlayableItem item) { if (item == null || item.getInformation() == null) return;//ww w.j av a 2 s . c o m ArrayList<Information> information = item.getInformation(); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.songInfo); View view = getLayoutInflater().inflate(R.layout.layout_songinfo, null, false); LinearLayout linearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutInformation); Bitmap image = item.getImage(); if (image != null) { ImageView imageView = new ImageView(this); imageView.setImageBitmap(image); linearLayout.addView(imageView); } for (Information info : information) { TextView info1 = new TextView(this); info1.setTextAppearance(this, android.R.style.TextAppearance_Medium); info1.setText(getResources().getString(info.key)); TextView info2 = new TextView(this); info2.setText(info.value); info2.setPadding(0, 0, 0, 10); linearLayout.addView(info1); linearLayout.addView(info2); } builder.setView(view); builder.setPositiveButton(R.string.ok, null); builder.show(); }
From source file:com.milton.common.widget.slidetablayout.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)}. *//* w w w.j av a 2 s. 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); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); textView.setBackgroundResource(outValue.resourceId); textView.setAllCaps(true); int padding_horizontal = (int) (TAB_VIEW_PADDING_DIPS_HORIZONTAL * getResources().getDisplayMetrics().density); int padding_vertical = (int) (TAB_VIEW_PADDING_DIPS_VERTICAL * getResources().getDisplayMetrics().density); textView.setPadding(padding_horizontal, padding_vertical, padding_horizontal, padding_vertical); if (mTabTextBackgroundResId != -1) { textView.setBackgroundResource(mTabTextBackgroundResId); } if (mTabTextColorId != -1) { textView.setTextColor(getResources().getColorStateList(mTabTextColorId)); } if (mTabTextSize != -1) { textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTabTextSize); } return textView; }
From source file:com.moorle.bookkeeping.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)}.// www .ja v a 2 s . c om */ 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); textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 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); return textView; }