本文整理匯總了Java中android.widget.TextView.getBackground方法的典型用法代碼示例。如果您正苦於以下問題:Java TextView.getBackground方法的具體用法?Java TextView.getBackground怎麽用?Java TextView.getBackground使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.TextView
的用法示例。
在下文中一共展示了TextView.getBackground方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setLabels
import android.widget.TextView; //導入方法依賴的package包/類
private void setLabels(TeamIssue issue) {
if (issue.getLabels() == null || issue.getLabels().isEmpty()) {
mLLlabels.setVisibility(View.GONE);
} else {
for (TeamIssue.Label label : issue.getLabels()) {
TextView text = (TextView) LayoutInflater.from(getActivity())
.inflate(R.layout.team_issue_lable, null, false);
text.setText(label.getName());
String colorStr = label.getColor();
if (colorStr.equalsIgnoreCase("#ffffff")) {
colorStr = "#000000";
}
int color = Color.parseColor(colorStr);
LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.setMargins(4, 0, 4, 0);
GradientDrawable d = (GradientDrawable) text.getBackground();
d.setStroke(1, color);
text.setTextColor(color);
mLLlabels.addView(text, params);
}
}
}
示例2: getCourseView
import android.widget.TextView; //導入方法依賴的package包/類
/**
* 有課程的格子
* @return
*/
public TextView getCourseView(SScheduleViewModelInterface data) {
TextView couseInfoTV = new TextView(mContext);
couseInfoTV.setText(data.getCourseName() + "\n" + data.getClassRoom());
couseInfoTV.setTextColor(Color.WHITE);
couseInfoTV.setGravity(Gravity.CENTER);
// couseInfoTV.setPadding(oneW, oneW, oneW, oneW);
couseInfoTV.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
couseInfoTV.setEllipsize(TextUtils.TruncateAt.END);
couseInfoTV.setLines(7);
// 設置背景顏色
int bg = new Random().nextInt(SScheduleTheme.COURSE_BG.length - 1);
couseInfoTV.setBackgroundResource(SScheduleTheme.COURSE_BG[bg]);
if (data.getBackColor() != 0) {
GradientDrawable myGrad = (GradientDrawable) couseInfoTV.getBackground();
myGrad.setColor(data.getBackColor());
}
return couseInfoTV;
}
示例3: captureTextBitmap
import android.widget.TextView; //導入方法依賴的package包/類
private static Bitmap captureTextBitmap(TextView textView) {
Drawable background = textView.getBackground();
textView.setBackground(null);
int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
if (width == 0 || height == 0) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
textView.draw(canvas);
textView.setBackground(background);
return bitmap;
}
示例4: init
import android.widget.TextView; //導入方法依賴的package包/類
protected void init(Context mContext) {
LayoutInflater iflater = LayoutInflater.from(mContext);
iflater.inflate(R.layout.common_bubble_dialog_left, this);
mTextView = (TextView) findViewById(R.id.common_bubble_left_text);
mTextView.setOnTouchListener(this);
mListDrawable = (LevelListDrawable) mTextView.getBackground();
}
示例5: setTextViewColor
import android.widget.TextView; //導入方法依賴的package包/類
private void setTextViewColor(TextView view, int color) {
if (color == ORIGIN_COLOR) {
view.setTextColor(mOriginBarTitleColor);
if (view.getBackground() != null) {
view.getBackground().clearColorFilter();
}
} else {
view.setTextColor(color);
if (view.getBackground() != null) {
view.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
}
示例6: setViewColor
import android.widget.TextView; //導入方法依賴的package包/類
private void setViewColor(TextView view, int color) {
if (color == ORIGIN_COLOR) {
view.setTextColor(mOriginBarTitleColor);
if (view.getBackground() != null) {
view.getBackground().clearColorFilter();
}
} else {
view.setTextColor(color);
if (view.getBackground() != null) {
view.getBackground().setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
}
}
示例7: getView
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//create a view
View listItemView=convertView;
//check for existing view,otherwise inflate a new layout
if(listItemView==null){
listItemView= LayoutInflater.from(getContext()).inflate(R.layout.earthquake_list_item,parent,false);
}
//find the earthquake at the given position in the list
Earthquake currentEarthquake=getItem(position);
//calling format method
String magnitude=formatMagnitude(currentEarthquake.getmMagnitude());
//find textView with id magnitude
TextView magnitudeView=(TextView) listItemView.findViewById(R.id.magnitude);
//Display the magnitude of current earthquake in that textView
magnitudeView.setText(magnitude);
//setting color of circle for magnitude
// Set the proper background color on the magnitude circle.
// Fetch the background from the TextView, which is a GradientDrawable.
GradientDrawable magnitudeCircle = (GradientDrawable) magnitudeView.getBackground();
// Get the appropriate background color based on the current earthquake magnitude
int magnitudeColor = getMagnitudeColor(currentEarthquake.getmMagnitude());
// Set the color on the magnitude circle
magnitudeCircle.setColor(magnitudeColor);
String originalLocation = currentEarthquake.getmLocation();
String primaryLocation;
String locationOffset;
if (originalLocation.contains(LOCATION_SEPARATOR)) {
String[] parts = originalLocation.split(LOCATION_SEPARATOR);
locationOffset = parts[0] + LOCATION_SEPARATOR;
primaryLocation = parts[1];
} else {
locationOffset = getContext().getString(R.string.near_the);
primaryLocation = originalLocation;
}
TextView primaryLocationView = (TextView) listItemView.findViewById(R.id.primary_location);
primaryLocationView.setText(primaryLocation);
TextView locationOffsetView = (TextView) listItemView.findViewById(R.id.location_offset);
locationOffsetView.setText(locationOffset);
// Create a new Date object from the time in milliseconds of the earthquake
Date dateObject = new Date(currentEarthquake.getmDate());
// Find the TextView with view ID date
TextView dateView = (TextView) listItemView.findViewById(R.id.date);
// Format the date string (i.e. "Mar 3, 1984")
String formattedDate = formatDate(dateObject);
// Display the date of the current earthquake in that TextView
dateView.setText(formattedDate);
// Find the TextView with view ID time
TextView timeView = (TextView) listItemView.findViewById(R.id.time);
// Format the time string (i.e. "4:30PM")
String formattedTime = formatTime(dateObject);
// Display the time of the current earthquake in that TextView
timeView.setText(formattedTime);
//return the listItemView set with appropriate date
return listItemView;
}
示例8: onBindViewHolder
import android.widget.TextView; //導入方法依賴的package包/類
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
Model model = items.get(position);
if (model == null) {
return;
}
RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
RecyclerView.LayoutParams lp2 = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
switch (model.getType()) {
case Model.TEXT_TYPE:
case Model.COMMENT_TYPE:
TextView textView = (TextView) model.getTheContent();
((ViewHolderText) holder).text.setText(textView.getText());
((ViewHolderText) holder).text.setPadding(textView.getPaddingLeft(), textView.getPaddingTop(), textView.getPaddingRight(), textView.getPaddingBottom());
((ViewHolderText) holder).text.setTypeface(textView.getTypeface());
((ViewHolderText) holder).text.setTextColor(textView.getCurrentTextColor());
if (android.os.Build.VERSION.SDK_INT > Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
((ViewHolderText) holder).text.setBackground(textView.getBackground());
}
if (textView.getBackground() != null) {
((ViewHolderText) holder).text.setAllCaps(true);
}
// Tag doesn't expand horizontally to the max
if (textView.getLayoutParams() != null) {
((ViewHolderText) holder).text.setLayoutParams(textView.getLayoutParams());
} else {
((ViewHolderText) holder).text.setLayoutParams(lp);
}
((ViewHolderText) holder).text.setTextSize(TypedValue.COMPLEX_UNIT_PX, textView.getTextSize());
break;
case Model.IMAGE_TYPE:
String imageURI = (String) model.getTheContent();
((ViewHolderImage) holder).image.setLayoutParams(lp);
Picasso.with(((ViewHolderImage) holder).image.getContext()).load(imageURI).into(((ViewHolderImage) holder).image);
break;
case Model.TWEET_TYPE:
CardView cardView = (CardView) model.getTheContent();
TextView tweet = (TextView) cardView.getChildAt(0);
Button link = (Button) cardView.getChildAt(1);
((ViewHolderTweet) holder).getTweet().setText(tweet.getText());
((ViewHolderTweet) holder).getLink().setContentDescription(link.getContentDescription());
break;
case Model.GRAPH_TYPE_BARS:
Chart chart1 = (Chart) model.getTheContent();
((ViewHolderChart) holder).chart.setData(chart1.getData());
((ViewHolderChart) holder).chart.setLayoutParams(lp2);
break;
case Model.GRAPH_TYPE_COLUMNS:
Chart chart2 = (Chart) model.getTheContent();
((ViewHolderChart) holder).chart.setData(chart2.getData());
((ViewHolderChart) holder).chart.setLayoutParams(lp2);
break;
}
}
示例9: getView
import android.widget.TextView; //導入方法依賴的package包/類
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
}
DATA k = getItem(position);
String originalLocation = k.getMquakeplace();
String primaryLocation;
String locationOffset;
if (originalLocation.contains(LOCATION_SEPAROTOR)) {
String parts[] = originalLocation.split(LOCATION_SEPAROTOR);
locationOffset = parts[0] + LOCATION_SEPAROTOR;
primaryLocation = parts[1];
} else
{
locationOffset = getContext().getString(R.string.near_the);
primaryLocation = originalLocation;
}
DecimalFormat format = new DecimalFormat("0.00");
String mag = format.format(k.getMquakemag());
TextView textView = (TextView) listItemView.findViewById(R.id.quakemag);
textView.setText("" + mag);
GradientDrawable magnitudeCircle = (GradientDrawable) textView.getBackground();
int magnitudeColor=getMagnitudeColor(k.getMquakemag());
magnitudeCircle.setColor(magnitudeColor);
TextView placetextView =(TextView) listItemView.findViewById(R.id.quakeplace);
placetextView.setText("" + primaryLocation);
TextView placetextView1=(TextView) listItemView.findViewById(R.id.quakeplace1);
placetextView1.setText("" + locationOffset);
TextView datetextView = (TextView) listItemView.findViewById(R.id.quakedate);
Date dateObject = new Date(k.getMquakedate());
SimpleDateFormat dateFormat = new SimpleDateFormat("LLL dd, yyyy");
dateFormat.format(dateObject);
datetextView.setText("" + dateFormat.format(dateObject));
TextView timeview = (TextView) listItemView.findViewById(R.id.quaketime);
Date datetime = new Date(k.getMquakedate());
SimpleDateFormat dateFormat1 = new SimpleDateFormat("h:mm a");
dateFormat1.format(datetime);
timeview.setText("" + dateFormat1.format(datetime));
return listItemView;
}