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);
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); } });
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();
/** * 把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)); }
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); } } });
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; } }
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); } });
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
@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)); }
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; } }); }
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; } }); }