属性 | 含义 |
android:colorPrimary | 标题栏颜色 |
android:colorPrimaryDark | 状态栏颜色 |
android:textColorPrimary | 主要文本颜色 |
android:textColorSecondary | 次要文本颜色 |
android:navigationBarColor | 底部导航栏颜色 |
android:windowBackground | 默认背景颜色 |
colorAccent | 控件在活动状态的颜色 |
<!-- 让背景颜色与应用默认的窗体背景颜色值一致 --> android:background="?android:windowBackground" |
public static int mTheme = -1; |
@Override protected void onCreate(Bundle savedInstanceState) { if (mTheme != -1) { setTheme(mTheme); } super.onCreate(savedInstanceState); …… } |
private void setTheme(int index) { switch (index) { case DEFAULT_THEME: MainActivity.mTheme = R.style.DefaultTheme; break; case DEFAULT_LIGHT_THEME: MainActivity.mTheme = R.style.DefaultLightTheme; break; case DEFAULT_LIGH_DARK_THEME: MainActivity.mTheme = R.style.DefaultLightDarkTheme; break; case RED_THEME: MainActivity.mTheme = R.style.RedTheme: break; …… default: break; } } |
protected void reload() { // 获取开启这个Activity时的那个Intent Intent intent = getActivity().getIntent(); // 取消关闭Activity时的默认动画 getActivity().overridePendingTransition(0, 0); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // 关闭Activity getActivity().finish(); // 取消开启Activity时的默认动画 getActivity().overridePendingTransition(0, 0); // 重启Activity startActivity(intent); } |
<!-- 阴影的作用 --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:orientation="vertical"> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center_horizontal" android:layout_marginTop="10dp" android:background="@drawable/circle_shape" android:elevation="5dp" android:gravity="center" android:text="高度5dp" /> <TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_gravity="center_horizontal" android:layout_marginTop="-20dp" android:background="@drawable/head" android:elevation="10dp" android:gravity="center" android:text="高度10dp" /> </LinearLayout> |
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval"> <!-- 边框 --> <stroke android:width="1dip" android:color="#eaff35" /> <!-- 填充 --> <solid android:color="#eaff35" /> </shape> |
<TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_margin="10dp" android:background="@drawable/circle_shape" android:elevation="10dp" android:gravity="center" android:outlineProvider="background" android:text="background" /> |
/** * 自定义阴影 */private void initShadow() { mTvShapeAlpha.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, view.getWidth(), view.getHeight()); } }); mTvImg.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, view.getWidth(), view.getHeight()); } }); } |
<TextView android:layout_width="100dp" android:layout_height="100dp" android:layout_margin="10dp" android:background="#88FF0000" android:elevation="5dp" android:gravity="center" android:text="原始图像" /> |
/** * 阴影的裁剪 */private void clipShadow() { // 三角形的阴影 ViewOutlineProvider triangleProvider = new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { Path path = new Path(); path.moveTo(view.getWidth() / 2, 0); path.lineTo(0, view.getHeight()); path.lineTo(view.getWidth(), view.getHeight()); path.close(); outline.setConvexPath(path); Log.e(TAG, "三角形阴影,是否可裁剪:" +outline.canClip()); } }; // 圆形的阴影 ViewOutlineProvider ovalProvider = new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { outline.setOval(0, 0, view.getWidth(), view.getHeight()); Log.e(TAG, "圆形阴影,是否可裁剪:" +outline.canClip()); } }; // 设置阴影 mTvTriangle.setOutlineProvider(triangleProvider); mTvOval.setOutlineProvider(ovalProvider); // 裁剪控件 mTvTriangle.setClipToOutline(true); mTvOval.setClipToOutline(true); } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |