android-layout material-design bottomnavigationview material-components-android material-you
有没有办法让菜单与页眉和页脚重叠?
我正在使用androidx.compose.material3.Scaffold和NavigationDrawer。
似乎脚手架的抽屉插槽已被删除 - https://android-review.googlesource.com/c/platform/frameworks/support/+/1896804因此https://developer.android.com/jetpack/compose上的说明/layouts/material?hl=hu#drawers不再适用。
android material-design material-components-android android-jetpack-compose android-jetpack-compose-material3
我试图在BottomNavigationView没有使用任何库的情况下为项目添加徽章,但不知何故BottomNavigationView没有显示徽章(custom_view)
main_view.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.hrskrs.test.MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:itemBackground="@color/colorPrimary"
app:itemIconTint="@color/colorAccent"
app:itemTextColor="@color/colorPrimaryDark"
app:menu="@menu/bottom_navigation_main" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
bottom_navigation_menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/item_test"
android:icon="@mipmap/ic_launcher"
android:title="action1"
app:showAsAction="always" />
<item
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:title="action2"
app:showAsAction="ifRoom" />
<item
android:enabled="true"
android:icon="@mipmap/ic_launcher"
android:title="action3"
app:showAsAction="ifRoom" />
</menu>
Run Code Online (Sandbox Code Playgroud)
活动扩展自AppCompatActivity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu = bottomNavigationView.getMenu();
menu.clear();
getMenuInflater().inflate(R.menu.bottom_navigation_main, menu);
MenuItem item = menu.findItem(R.id.item_test);
item = MenuItemCompat.setActionView(item, R.layout.custom_view); …Run Code Online (Sandbox Code Playgroud) android android-layout bottomnavigationview material-components material-components-android
在我的一个应用程序中,我将Theme.MaterialComponents.Light.NoActionBar用作基本样式。在我称之为 的这种样式中,AppTheme我试图覆盖editTextStyle以提供自定义样式com.google.android.material.textfield.TextInputEditText(根据源代码,它R.attr.editTextStyle用作默认样式)。
这是我当前的主题,与 TIEditText 和 TILayout 相关:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
[ primary and secondary colors, OnColors, etc.]
<item name="editTextStyle">@style/AppTheme.TextInputEditText</item>
<item name="textInputStyle">@style/AppTheme.TextInputLayout</item>
[ Custom attribute for testing, defined in attrs.xml ]
<item name="textInputEditTextStyle">@style/AppTheme.TextInputEditText</item>
</style>
Run Code Online (Sandbox Code Playgroud)
出于某种原因,即使我设置了editTextStyle,如果我在代码中使用它,它也不会被应用:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilFirstName"
style="?attr/textInputStyle"
android:hint="@string/label_firstname"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstName"
style="?attr/editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="@={viewModel.firstName}" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
但是,如果我替换firstNamewith的样式?attr/textInputEditTextStyle,它会起作用。
为什么我不能覆盖editTextStyle默认主题?这到底是怎么回事?
目标 SDK 为 28,minSDK 为 21,材质库版本为 1.1.0-alpha06
android android-edittext android-textinputlayout material-components material-components-android
我试图创建一个AutoCompleteTextView,被一个TextInputLayout. 根据文档,我应该使用这种风格:
Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu
Run Code Online (Sandbox Code Playgroud)
但我无法解决这种风格。Android Studio 说我只能使用:
@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense
@style/Widget.MaterialComponents.TextInputLayout.FilledBox
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense
@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox
Run Code Online (Sandbox Code Playgroud)
我的项目使用
implementation 'com.android.support:design:28.0.0'
Run Code Online (Sandbox Code Playgroud)
最终结果应如下所示:
Widget.MaterialComponents.TextInputLayout.*.ExposedDropdownMenu
Run Code Online (Sandbox Code Playgroud) 这是我的应用主题:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
由于未使用所需的主题,我遇到了膨胀错误。在Manifest我没有覆盖我收到此错误的活动的主题,因此使用了定义的 AppTheme styles.xml。
错误:
android.view.InflateException: Binary XML file line #122: Binary XML file line #122: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #122: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at android.view.LayoutInflater.createView(LayoutInflater.java:647)
...
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:240)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:215)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:143)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:116)
Run Code Online (Sandbox Code Playgroud)
这是我的 xml:
<com.google.android.material.textfield.TextInputLayout …Run Code Online (Sandbox Code Playgroud) 我有这个问题,我不知道它来自哪里,我已经用自定义背景创建了这个按钮,但是背景颜色是原色,除非更改原色,否则无法更改它。
<Button
android:id="@+id/btn_teacher"
style="@style/normalText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_16sdp"
android:background="@drawable/btn_rounded_stroke"
android:text="@string/txt_teacher" />
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
<color name="bg_color">#FFD7A4</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
我有很多不同颜色的按钮,所以我不能改变原色
这是我的可绘制背景
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item >
<shape android:shape="rectangle" >
<size android:height="@dimen/_48sdp" />
<corners android:radius="@dimen/_24sdp" />
<stroke android:width="@dimen/_1sdp" android:color="#59CECE" />
<solid android:color="@android:color/white"/>
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我正在使用谷歌的新材料设计
implementation "com.google.android.material:material:1.3.0-alpha02"
Run Code Online (Sandbox Code Playgroud)
我怎样才能覆盖这种颜色?

xml android button android-button material-components-android
在将我的应用程序迁移到 Jetpack compose 的过程中,我遇到了应用程序中 TextField 需要自动完成功能的部分。
但是,从版本 1.0.0-alpha05 开始,我找不到任何使用 Compose API 实现此目的的功能。我发现的最接近的东西是DropdownMenu和DropdownMenuItem可组合项,但似乎需要大量手动管道才能从中创建自动完成菜单。
当然,显而易见的事情就是等待 Jetpack Compose 的未来更新。但我想知道,在迁移中遇到此问题的人是否找到了解决方案?
我希望保持工具提示值始终可见,并且工具提示的文本应该背景透明。我尝试了https://github.com/material-components/material-components-android/blob/master/docs/components/Slider.md但没有办法让工具提示始终可见
<com.google.android.material.slider.Slider
android:id="@+id/slider_sound_sensitivity"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:valueFrom="0.0"
android:valueTo="100.0"
android:layout_marginTop="@dimen/_8sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.508"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_sound_sensitivity" />
<com.google.android.material.slider.RangeSlider
android:id="@+id/range_humidity_in_percentage"
style="@style/Myslider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:valueFrom="0.0"
android:valueTo="100.0"
android:layout_marginTop="@dimen/_16sdp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_humidity_in_percentage"
app:values="@array/initial_slider_values" />
Run Code Online (Sandbox Code Playgroud) 如何设置material3卡的标高?我正在使用新的material3卡并收到错误
此材质 API 是实验性的,将来可能会更改或删除。
这是代码->
@ExperimentalMaterial3Api
@Composable
fun ProfileCard(
modifier: Modifier = Modifier
) {
Card(
modifier = modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(all = 16.dp),
shape = RoundedCornerShape(size = 16.dp),
containerColor = MaterialTheme.colorScheme.surface,
border = BorderStroke(width = 1.dp, color = MaterialTheme.colorScheme.inverseOnSurface),
elevation = CardDefaults.outlinedCardElevation()
) {
...
}
}
Run Code Online (Sandbox Code Playgroud)
由于海拔引起的错误,我无法运行应用程序如何设置海拔?
编辑:通过添加解决了问题
elevation = CardDefaults.outlinedCardElevation(defaultElevation = 1.dp)
Run Code Online (Sandbox Code Playgroud)
为什么我们必须为CardDefaults.outlinedCardElevation添加边框,为什么它默认不显示?
android material-design material-components-android android-jetpack-compose android-jetpack-compose-material3
material-components-android ×10
android ×9
android-jetpack-compose-material3 ×2
button ×1
kotlin ×1
material-you ×1
xml ×1