我需要AppTheme.colorAccent棕色,但我需要我的Snackbar动作颜色是蓝色。如何Snackbar在不改变样式的情况下更改操作按钮的颜色AppTheme.colorAccent?
我已经尝试过这段代码,但它不起作用:
<style name="TextAppearance.Design.Snackbar" parent="android:TextAppearance" tools:override="true">
<item name="colorAccent">#3097ff</item>
</style>
Run Code Online (Sandbox Code Playgroud) android snackbar android-snackbar material-components material-components-android
Theme.MaterialComponents....如果我想在Activity 中使用主题drawableLeft/Right等,那么它们不会显示。但是,如果我使用主题,Base.Theme.AppCompat它们会按预期工作。这是按钮:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test Button"
android:drawableLeft="@drawable/ic_envelope"/>
Run Code Online (Sandbox Code Playgroud)
这就是主题的外观 Base.Theme.MaterialComponents

如何drawableLeft使用Base.Theme.MaterialComponents主题进行工作?
android android-button material-design material-components material-components-android
E/OpenGLRenderer: resultIndex is -1, the polygon must be invalid!
A/OpenGLRenderer: Error: Spot pair overflow!!! used 38, total 22
A/libc: Fatal signal 6 (SIGABRT), code -6 in tid 11996 (hwuiTask1)
Run Code Online (Sandbox Code Playgroud)
使用 shapeAppearance 属性会导致崩溃。
这是 XML 中的 FAB
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
style="@style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin"
android:onClick="@{() -> callback.add(viewModel.plant)}"
android:tint="@android:color/white"
app:shapeAppearance="@style/ShapeAppearance.Sunflower.FAB" <--
app:isGone="@{viewModel.isPlanted}"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_plus" />
Run Code Online (Sandbox Code Playgroud)
下面是 shapeAppearance 的样式,
<style name="ShapeAppearance.Sunflower.FAB" parent="ShapeAppearance.MaterialComponents">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopLeft">0dp</item>
<item name="cornerSizeTopRight">30dp</item>
<item name="cornerSizeBottomRight">0dp</item>
<item name="cornerSizeBottomLeft">30dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这解决了崩溃。
<style name="ShapeAppearance.Sunflower.FAB" parent="ShapeAppearance.MaterialComponents">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopLeft">0dp</item> <--
<item …Run Code Online (Sandbox Code Playgroud) android floating-action-button material-components android-jetpack material-components-android
我第一次使用材料芯片。
问题:
我正在使用以下代码动态添加芯片。请检查我写的app:singleSelection="true"对我很重要的内容。即使它一次选择多个芯片。
我想一次只选择一个带有刻度线的芯片。
XML 代码:
<com.google.android.material.chip.ChipGroup
android:id="@+id/categoryChipsView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
app:chipSpacing="10dp"
app:singleSelection="true"
app:itemSpacing="15dp"
app:singleLine="true">
</com.google.android.material.chip.ChipGroup>
Run Code Online (Sandbox Code Playgroud)
Java代码:
private void addChipView(String chipText) {
View child = getLayoutInflater().inflate(R.layout.row_chip_view, null);
Chip chip = child.findViewById(R.id.chip);
chip.setText(chipText);
chip.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, ((Chip) v).getText(), Toast.LENGTH_SHORT).show();
}
});
// This is ChipGroup view
binding.categoryChipsView.addView(child);
}
Run Code Online (Sandbox Code Playgroud)
row_chip_view.xml
<com.google.android.material.chip.Chip xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/chip"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="@string/app_name"
android:textColor="@android:color/white"
app:checkedIcon="@drawable/ic_check"
app:chipBackgroundColor="@color/colorAccent"
app:chipEndPadding="8dp"
app:chipIconTint="@android:color/white"
app:chipStartPadding="8dp" …Run Code Online (Sandbox Code Playgroud) android android-chips material-components material-components-android
起初,我的应用程序使用<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">样式。但是我将其更改为 Material Components <style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">(为了使用标签的材质徽章计数)。所以改变后的样式是这样的:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green</item>
<item name="colorAccent">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
更改样式后,溢出菜单背景现在为白色。(之前是绿底白字Theme.AppCompat.Light.DarkActionBar)。但是现在背景是白色的,文字也是白色的。
这是工具栏的xml:
<androidx.appcompat.widget.Toolbar
android:id="@+id/ev_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme">
</androidx.appcompat.widget.Toolbar>
Run Code Online (Sandbox Code Playgroud)
和工具栏的主题样式:
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:textColorPrimary">@color/white</item>
<item name="android:colorBackground">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我尝试<item name="popupMenuStyle">@style/CustomPopup</item>在AppThemewith 中设置
<style name="CustomPopup" parent="@style/Widget.MaterialComponents.PopupMenu">
<item name="android:popupBackground">@color/green</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但仍然没有运气。
我用来测试的设备使用的是 Android 8.0,compileSdkVersion并且targetSdkVersion是 28。
感谢您的时间。
xml android android-theme material-components material-components-android
我尝试TextInputLayout使用 new实现prefixText,使用com.google.android.material:material:1.2.0-alpha02. 这是一个非常酷的功能,但是当我添加前缀文本时,提示标签会浮动并在前缀之后对齐。这看起来不太好,特别是如果您在同一页面上有更多没有前缀的输入字段,浮动标签不会对齐。
我的布局代码的相关部分:
<LinearLayout
android:id="@+id/login_input_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_username_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username_hint"
app:prefixText="Prefix">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/login_username_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/login_password_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/default_margin"
android:imeOptions="actionDone"
app:endIconMode="password_toggle">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password_hint"
android:inputType="textPassword"
android:singleLine="true"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android android-textinputlayout material-components material-components-android
如何拥有一个curcular ImageView。这是我的 xml
<RelativeLayout
android:id="@+id/imgUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="@drawable/circle_border">
<ImageView
android:id="@+id/studentimg"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_margin="9dp"
android:adjustViewBounds="true"
android:background="@drawable/circlepf"
android:padding="3dp"
android:scaleType="centerInside"
android:src="@drawable/ic_profile" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的问题图像样本

但我希望这张图片显示在 circular view
java xml android material-components material-components-android
我想将箭头颜色更改为白色。怎么做?这是我的代码
<com.google.android.material.textfield.TextInputLayout
style="@style/ExposedDropdownMenu"
android:hint="Select"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:focusable="false"
android:textSize="17sp"
android:padding="15dp"
android:textColorHint="@color/white"
android:textColor="@color/white"
android:id="@+id/actv_pool"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:ignore="LabelFor" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的风格:
<style name="ExposedDropdownMenu" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu">
<item name="boxStrokeColor">#fff</item>
<item name="boxStrokeWidth">1dp</item>
<item name="android:textColorHint">#fff</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我希望很清楚。提前致谢。
android material-design android-textinputlayout material-components material-components-android
android android-toolbar material-components material-components-android androidx