Android 如何在TextView中创建阴影?
我有一个在TextView中创建阴影的要求 我怎样才能做到呢?附加屏幕排序 如果你有任何想法,请告诉我Android 如何在TextView中创建阴影?,android,android-layout,layout,textview,Android,Android Layout,Layout,Textview,我有一个在TextView中创建阴影的要求 我怎样才能做到呢?附加屏幕排序 如果你有任何想法,请告诉我 谢谢!!!提前。在XML中添加高程属性。将其设置为5dp <TextView android:id="@+id/myText" ... android:elevation="5dp" /> 在XML中添加高程属性。将其设置为5dp <TextView android:id="@+id/myText" ... android:
谢谢!!!提前。在XML中添加高程属性。将其设置为5dp
<TextView
android:id="@+id/myText"
...
android:elevation="5dp" />
在XML中添加高程属性。将其设置为5dp
<TextView
android:id="@+id/myText"
...
android:elevation="5dp" />
在API>=21上,您可以直接使用
CustomViewOutlineProvider
CustomViewOutlineProvider.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class CustomViewOutlineProvider extends ViewOutlineProvider {
int roundCorner;
public CustomViewOutlineProvider(int round) {
roundCorner = round;
}
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), roundCorner);
}
}
活动
TextView textView = (TextView) findViewById(R.id.shadow_txt);
textView.setOutlineProvider(new CustomViewOutlineProvider(30));
textView.setClipToOutline(true);
对于预列印设备(API>=21上的API),您可以直接使用
CustomViewOutlineProvider
CustomViewOutlineProvider.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class CustomViewOutlineProvider extends ViewOutlineProvider {
int roundCorner;
public CustomViewOutlineProvider(int round) {
roundCorner = round;
}
@Override
public void getOutline(View view, Outline outline) {
outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), roundCorner);
}
}
活动
TextView textView = (TextView) findViewById(R.id.shadow_txt);
textView.setOutlineProvider(new CustomViewOutlineProvider(30));
textView.setClipToOutline(true);
用于预列印设备(如果您在Android Studio中找到shadowDx
shadowDyshadowRadiusshadowColor
方法,请使用它们有什么问题?您将在Android Studio中找到shadowDxshadowDy
shadowRadius
shadowColor
方法有什么问题,请使用它们estion?这不会导致发问者的图片!!而且它在Android版本中有限制它只在棒棒糖中工作+这不会导致发问者的图片!!而且它在Android版本中有限制它只在棒棒糖中工作+
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorPrimary"/>
<corners android:radius="20dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="alpha_15">#26000000</color>
</resources>