2

我有一个文本视图:

<TextView
      android:id="@+id/textAfter"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="example string"
      android:textColor="@android:color/transparent"
      android:textSize="40sp"
      />

此 textView 稍后以编程方式以一系列方式进行修改:

imageView_Source = (TextView)findViewById(R.id.source);
textAfter = (TextView)findViewById(R.id.textAfter);

X_FONT = Typeface.createFromAsset(getResources().getAssets(), "ROCKB.TTF");
//textAfter = new TextView(getApplicationContext());
textAfter.setTypeface(X_FONT);
localTextPaint = textAfter.getPaint();
localTextPaint.setTextScaleX(1f);     
localTextPaint.setFakeBoldText(true);
localTextPaint.setAntiAlias(true);
localTextPaint.setSubpixelText(true);
localTextPaint.setMaskFilter(new EmbossMaskFilter(new float[] { 1, 1, 1 },ambientValue, specularValue, blurRadiusValue));

public void onClick(View v) {
      //textAfter.invalidate();
      localTextPaint.setMaskFilter(null);
      textAfter.invalidate();
      localTextPaint.setMaskFilter(new EmbossMaskFilter(new float[] { 1, 1, 1 },ambientValue, specularValue, blurRadiusValue));
      textAfter.invalidate();

}};

onClick 纯粹用于测试目的。但是,如果我添加以下内容:

 android:shadowColor="#000000"
 android:shadowDx="3.0"
 android:shadowDy="3.0"
 android:shadowRadius="1.0"

文本变得完全不可见。虽然阴影和蒙版在单独应用时都有效,但在统一应用时都不起作用(文本不会直接出现)。我猜这也与应用于阴影的蒙版有关,但我对 Android 编码还很陌生,所以我真的不知道是什么原因造成的,也不知道如何修复它。

提前致谢。

4

3 回答 3

1

我遇到了同样的事情,我意识到这是由于硬件加速。

要为特定视图禁用硬件加速,请执行以下操作:

<TextView>.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
于 2013-12-21T23:12:27.903 回答
0

我的项目中存在同样的问题。我能够重现这种行为。尝试了一些东西,没有任何效果。我更喜欢 *.9.png 。

如果您不想使用 png,这种方法看起来很有趣http://qwerjk.com/magic-text

于 2013-02-22T22:45:43.370 回答
0

我在下面使用相同对象的简化透明副本,仅给它阴影,而前景中的原始副本设置为浮雕。

于 2016-11-26T20:08:37.167 回答