| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 移动开发 -> Android 特殊形状View的福音 : ShapeableImageView 再也不用画各种Shape了 -> 正文阅读 |
|
[移动开发]Android 特殊形状View的福音 : ShapeableImageView 再也不用画各种Shape了 |
全新的?ShapeableImageView?widget 是?AppCompatImageView?的扩展,用于处理形状主题 (shape theming)。常见用例是对矩形源图像进行圆角遮罩。不过,该 widget 也支持各种圆角尺寸、切角以及不同的描边宽度和颜色。
Getting started with Material Components for Android1. Depend on our libraryMaterial Components for Android is available through Google's Maven Repository. To use it: Material Components themes The following is the list of Material Components themes you can use to get the latest component styles and theme-level attributes. Update your app theme to inherit from one of these themes, e.g.: <style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight"> <!-- ... --> </style> (在style.xml文件里面添加style example:
<!-- 圆角图片 --> <style name="roundedCornerImageStyle"> ? ? <item name="cornerFamily">rounded</item> ? ? <item name="cornerSize">25dp</item> </style> ) For more information on how to set up theme-level attributes for your app, take a look at our?Theming?guide, as well as our?Dark Theme?guide for why it's important to inherit from the? Note: Using a Material Components theme enables a custom view inflater which replaces default components with their Material counterparts. Currently, this only replaces? Bridge Themes If you cannot change your theme to inherit from a Material Components theme, you can inherit from a Material Components?Bridge?theme. <style name="Theme.MyApp" parent="Theme.MaterialComponents.Light.Bridge"> <!-- ... --> </style> Both? Bridge themes inherit from AppCompat themes, but also define the new Material Components theme attributes for you. If you use a bridge theme, you can start using Material Design components without changing your app theme. AppCompat Themes You can also incrementally test new Material components without changing your app theme. This allows you to keep your existing layouts looking and behaving the same, while introducing new components to your layout one at a time. However, you must add the following new theme attributes to your existing app theme, or you will encounter? <style name="Theme.MyApp" parent="Theme.AppCompat"> <!-- Original AppCompat attributes. --> <item name="colorPrimary">@color/my_app_primary_color</item> <item name="colorSecondary">@color/my_app_secondary_color</item> <item name="android:colorBackground">@color/my_app_background_color</item> <item name="colorError">@color/my_app_error_color</item> <!-- New MaterialComponents attributes. --> <item name="colorPrimaryVariant">@color/my_app_primary_variant_color</item> <item name="colorSecondaryVariant">@color/my_app_secondary_variant_color</item> <item name="colorSurface">@color/my_app_surface_color</item> <item name="colorOnPrimary">@color/my_app_color_on_primary</item> <item name="colorOnSecondary">@color/my_app_color_on_secondary</item> <item name="colorOnBackground">@color/my_app_color_on_background</item> <item name="colorOnError">@color/my_app_color_on_error</item> <item name="colorOnSurface">@color/my_app_color_on_surface</item> <item name="scrimBackground">@color/mtrl_scrim_color</item> <item name="textAppearanceHeadline1">@style/TextAppearance.MaterialComponents.Headline1</item> <item name="textAppearanceHeadline2">@style/TextAppearance.MaterialComponents.Headline2</item> <item name="textAppearanceHeadline3">@style/TextAppearance.MaterialComponents.Headline3</item> <item name="textAppearanceHeadline4">@style/TextAppearance.MaterialComponents.Headline4</item> <item name="textAppearanceHeadline5">@style/TextAppearance.MaterialComponents.Headline5</item> <item name="textAppearanceHeadline6">@style/TextAppearance.MaterialComponents.Headline6</item> <item name="textAppearanceSubtitle1">@style/TextAppearance.MaterialComponents.Subtitle1</item> <item name="textAppearanceSubtitle2">@style/TextAppearance.MaterialComponents.Subtitle2</item> <item name="textAppearanceBody1">@style/TextAppearance.MaterialComponents.Body1</item> <item name="textAppearanceBody2">@style/TextAppearance.MaterialComponents.Body2</item> <item name="textAppearanceCaption">@style/TextAppearance.MaterialComponents.Caption</item> <item name="textAppearanceButton">@style/TextAppearance.MaterialComponents.Button</item> <item name="textAppearanceOverline">@style/TextAppearance.MaterialComponents.Overline</item> </style> 5. Add a Material component to your appTake a look at our?documentation?for the full list of available Material components. Each component's page has specific instructions on how to implement it in your app. Let's use?text fields?as an example. Implementing a text field via XML The default?filled text field?XML is defined as: <com.google.android.material.textfield.TextInputLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/textfield_label"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content"/> </com.google.android.material.textfield.TextInputLayout> Note: If you are?not?using a theme that inherits from a Material Components theme, you will have to specify the text field style as well, via? Other text field styles are also provided. For example, if you want an?outlined text field?in your layout, you can apply the Material Components? <com.google.android.material.textfield.TextInputLayout style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/textfield_label"> <com.google.android.material.textfield.TextInputEditText android:layout_width="match_parent" android:layout_height="wrap_content"/> </com.google.android.material.textfield.TextInputLayout>
Last: 布局xml直接出效果 <!-- 圆角图片 --> <!-- shapeAppearanceOverlay或shapeAppearance 加载style --> <!-- strokeColo描边颜色 --> <!-- strokeWidth描边宽度 --> laste: <com.google.android.material.imageview.ShapeableImageView ? ? android:id="@+id/image1" ? ? android:layout_width="100dp" ? ? android:layout_height="100dp" ? ? android:padding="1dp" ? ? android:src="@mipmap/ic_launcher" ? ? app:shapeAppearanceOverlay="@style/roundedCornerImageStyle" ? ? app:strokeColor="#F44336" ? ? app:strokeWidth="2dp" /> ShapeableImageView GitHub:?https://github.com/material-components/material-components-android 个人GitHub:??https://github.com/HuaDanJson |
|
移动开发 最新文章 |
Vue3装载axios和element-ui |
android adb cmd |
【xcode】Xcode常用快捷键与技巧 |
Android开发中的线程池使用 |
Java 和 Android 的 Base64 |
Android 测试文字编码格式 |
微信小程序支付 |
安卓权限记录 |
知乎之自动养号 |
【Android Jetpack】DataStore |
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/23 0:28:07- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |