I have a TextView in my Activity to which I want to add a shadow. It is supposed to look like in OsmAnd (100% opaque):
But it looks like this:
I tried all the hacks, tips and tricks in the other posts like here, here and here.
None of them works that great or looks so good.
You use a FrameLayout (which has the characteristic of laying its components over each other) and put 2 TextViews inside at the same position.
MainActivity.xml:
And in the onCreate
method of your activity you set the stroke width of the shadow TextView and change it from FILL to STROKE:
import android.graphics.Paint;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//here comes the magic
TextView textViewShadow = (TextView) findViewById(R.id.textViewShadowId);
textViewShadow.getPaint().setStrokeWidth(5);
textViewShadow.getPaint().setStyle(Paint.Style.STROKE);
}
}
The result looks like this: