是否可以更改xml提升属性产生的阴影颜色?我希望通过代码动态更改阴影.
将我的代码删除到最小的例子:
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp">
<Button
android:id="@+id/my_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:elevation="10dp"
android:translationZ="10dp"
android:background="@android:color/holo_green_light"
android:text="BUTTON"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
我需要那种布局结构.
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Run Code Online (Sandbox Code Playgroud)
在Android Studio设计器中可以看到阴影:
但是在运行时没有显示:
测试: