本文整理了Java中android.widget.TextView.getBackground()
方法的一些代码示例,展示了TextView.getBackground()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TextView.getBackground()
方法的具体详情如下:
包路径:android.widget.TextView
类名称:TextView
方法名:getBackground
暂无
代码示例来源:origin: stackoverflow.com
TextView tv = (TextView)findViewById(R.id.image_test);
LayerDrawable ld = (LayerDrawable)tv.getBackground();
int topInset = tv.getHeight() / 2 ; //does not work!
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.image_test);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LayerDrawable ld = (LayerDrawable)tv.getBackground();
ld.setLayerInset(1, 0, tv.getHeight() / 2, 0, 0);
}
});
代码示例来源:origin: stackoverflow.com
TextView tv2 = (TextView) rl.findViewById(R.id.toggle_indicator);
/* Refer to http://developer.android.com/reference/android/graphics/drawable/GradientDrawable.html#mutate()
to understand why we need to mutate the GradientDrawable*/
GradientDrawable sd = (GradientDrawable) tv2.getBackground().mutate();
sd.setColor(0xff999999);
sd.invalidateSelf();
代码示例来源:origin: GitLqr/LQRWeChat
/**
* 把press图片、文字全部隐藏(设置透明度)
*/
private void setTransparency() {
mTvMessageNormal.getBackground().setAlpha(255);
mTvContactsNormal.getBackground().setAlpha(255);
mTvDiscoveryNormal.getBackground().setAlpha(255);
mTvMeNormal.getBackground().setAlpha(255);
mTvMessagePress.getBackground().setAlpha(1);
mTvContactsPress.getBackground().setAlpha(1);
mTvDiscoveryPress.getBackground().setAlpha(1);
mTvMePress.getBackground().setAlpha(1);
mTvMessageTextNormal.setTextColor(Color.argb(255, 153, 153, 153));
mTvContactsTextNormal.setTextColor(Color.argb(255, 153, 153, 153));
mTvDiscoveryTextNormal.setTextColor(Color.argb(255, 153, 153, 153));
mTvMeTextNormal.setTextColor(Color.argb(255, 153, 153, 153));
mTvMessageTextPress.setTextColor(Color.argb(0, 69, 192, 26));
mTvContactsTextPress.setTextColor(Color.argb(0, 69, 192, 26));
mTvDiscoveryTextPress.setTextColor(Color.argb(0, 69, 192, 26));
mTvMeTextPress.setTextColor(Color.argb(0, 69, 192, 26));
}
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.image_test);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LayerDrawable ld = (LayerDrawable)tv.getBackground();
ld.setLayerInset(1, 0, tv.getHeight() / 2, 0, 0);
ViewTreeObserver obs = tv.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
}
});
代码示例来源:origin: GitLqr/LQRWeChat
public void bottomBtnClick(View view) {
setTransparency();
switch (view.getId()) {
case R.id.llMessage:
mVpContent.setCurrentItem(0, false);
mTvMessagePress.getBackground().setAlpha(255);
mTvMessageTextPress.setTextColor(Color.argb(255, 69, 192, 26));
break;
case R.id.llContacts:
mVpContent.setCurrentItem(1, false);
mTvContactsPress.getBackground().setAlpha(255);
mTvContactsTextPress.setTextColor(Color.argb(255, 69, 192, 26));
break;
case R.id.llDiscovery:
mVpContent.setCurrentItem(2, false);
mTvDiscoveryPress.getBackground().setAlpha(255);
mTvDiscoveryTextPress.setTextColor(Color.argb(255, 69, 192, 26));
break;
case R.id.llMe:
mVpContent.setCurrentItem(3, false);
mTvMePress.getBackground().setAlpha(255);
mTvMeTextPress.setTextColor(Color.argb(255, 69, 192, 26));
break;
}
}
代码示例来源:origin: stackoverflow.com
final TextView tv = (TextView)findViewById(R.id.image_test);
ViewTreeObserver vto = tv.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
LayerDrawable ld = (LayerDrawable)tv.getBackground();
ld.setLayerInset(1, 0, tv.getHeight() / 2, 0, 0);
}
});
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: udacity/ud851-Exercises
/**
* Called by the RecyclerView to display data at a specified position in the Cursor.
*
* @param holder The ViewHolder to bind Cursor data to
* @param position The position of the data in the Cursor
*/
@Override
public void onBindViewHolder(TaskViewHolder holder, int position) {
// Determine the values of the wanted data
TaskEntry taskEntry = mTaskEntries.get(position);
String description = taskEntry.getDescription();
int priority = taskEntry.getPriority();
String updatedAt = dateFormat.format(taskEntry.getUpdatedAt());
//Set values
holder.taskDescriptionView.setText(description);
holder.updatedAtView.setText(updatedAt);
// Programmatically set the text and color for the priority TextView
String priorityString = "" + priority; // converts int to String
holder.priorityView.setText(priorityString);
GradientDrawable priorityCircle = (GradientDrawable) holder.priorityView.getBackground();
// Get the appropriate background color based on the priority
int priorityColor = getPriorityColor(priority);
priorityCircle.setColor(priorityColor);
}
代码示例来源:origin: GitLqr/LQRWeChat
@Override
public void initView() {
setToolbarTitle(UIUtils.getString(R.string.app_name));
mIbAddMenu.setVisibility(View.VISIBLE);
//等待全局数据获取完毕
showWaitingDialog(UIUtils.getString(R.string.please_wait));
//默认选中第一个
setTransparency();
mTvMessagePress.getBackground().setAlpha(255);
mTvMessageTextPress.setTextColor(Color.argb(255, 69, 192, 26));
//设置ViewPager的最大缓存页面
mVpContent.setOffscreenPageLimit(3);
mFragmentList.add(FragmentFactory.getInstance().getRecentMessageFragment());
mFragmentList.add(FragmentFactory.getInstance().getContactsFragment());
mFragmentList.add(FragmentFactory.getInstance().getDiscoveryFragment());
mFragmentList.add(FragmentFactory.getInstance().getMeFragment());
mVpContent.setAdapter(new CommonFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList));
}
代码示例来源:origin: stackoverflow.com
public void onCreate() {
setContentView(R.layout.main);
final TextView tv = (TextView)findViewById(R.id.image_test);
final LayerDrawable ld = (LayerDrawable)tv.getBackground();
final ViewTreeObserver obs = mTv.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw () {
Log.d(TAG, "onPreDraw tv height is " + tv.getHeight()); // bad for performance, remove on production
int height = tv.getHeight();
int topInset = height / 2;
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
return true;
}
});
}
代码示例来源:origin: stackoverflow.com
private int mLastTvHeight = 0;
public void onCreate() {
setContentView(R.layout.main);
final TextView tv = (TextView)findViewById(R.id.image_test);
final LayerDrawable ld = (LayerDrawable)tv.getBackground();
final ViewTreeObserver obs = mTv.getViewTreeObserver();
obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw () {
Log.d(TAG, "onPreDraw tv height is " + tv.getHeight()); // bad for performance, remove on production
int height = tv.getHeight();
if (height != mLastTvHeight) {
mLastTvHeight = height;
int topInset = height / 2;
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
}
return true;
}
});
}
内容来源于网络,如有侵权,请联系作者删除!