English 中文(简体)
更改文稿
原标题:Changing TextView Opacity in Android

因此,Im试图积极改变我的和roid中的“密码”的不透明性。 页: 1 我的分歧应该开始变得透明。 当umb在<条码>种子/条码>上半途时,案文应当完全透明。 I m 试图使用setAlpha(float)方法 对我的<代码>TextView的看法,但Eclipse对我说的setAlpha(<>未对加以界定。 我用错误的方式来形容这种方法? 还是有另一种方式改变不透明?

本条准则(staticText:,gameSelector:seekbar:

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch){
    classicText.setAlpha(gameSelector.getProgress());
}
最佳回答

您可以把甲型六氯环己烷同此刻一样。

int alpha = 0;
((TextView)findViewById(R.id.t1)).setTextColor(Color.argb(alpha, 255, 0, 0));

as the alpha you getting from the seekbar that will be set into the text color

问题回答

这为我工作:

<>1>。 创建<>AlphaTextView:

public class AlphaTextView extends TextView {

  public AlphaTextView(Context context) {
    super(context);
  }

  public AlphaTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public AlphaTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  @Override
  public boolean onSetAlpha(int alpha) 
  {
    setTextColor(getTextColors().withAlpha(alpha));
    setHintTextColor(getHintTextColors().withAlpha(alpha));
    setLinkTextColor(getLinkTextColors().withAlpha(alpha));
    getBackground().setAlpha(alpha);
    return true;
  }    
}

<>2>。 添加这段文字,而不是用文字写成文view:

...
   <!--use complete path to AlphaTextView in following tag-->
   <com.xxx.xxx.xxx.AlphaTextView
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="sample alpha textview"
         android:gravity="center"
         android:id="@+id/at"
         android:textColor="#FFFFFF"
         android:background="#88FF88"
        />
...

<>3>。 现在,你可以在你的活动中利用这一案文:

at=(AlphaTextView)findViewById(R.id.at);

at.onSetAlpha(255); // To make textview 100% opaque
at.onSetAlpha(0); //To make textview completely transperent

如今,在XML中,有一席之地。

甲型六氯环己烷

a. 通过Layout改变Opacity

改动方法:

public void onProgressChanged(SeekBar seekBar, int progress, boolean fromTouch)
{
    classicText.setAlpha((float)(gameSelector.getProgress())/(float)(seekBar.getMax()));
}

也许晚了,但如果现在有人想到这一点的话,你们都必须做到:

textView.setAlpha();

括号内的条目编号为0至1

I think this is a simple way to set alpha or opacity programmatically for TextView. By using function withAlpha after getTextColors from textView.

// alpha value between 0..255
// 0 for transparent
classicText.setTextColor(classicText.textColors.withAlpha(100))

页: 1 阿尔法(float xxx);

iii

int progress = gameSelector.getProgress();
int maxProgress = gameSelector.getMax();
float opacity = (progress / maxProgress)*255;
classicText.setAlpha(opacity);




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签