我正在尝试使用 Material Components 库在我的应用程序中实现 Material Design。我希望我的图标和后退箭头为白色,但我无法更改它们的颜色。我的代码哪里出错了?
我尝试在我的样式 'NITraffic.Toolbar' 中添加以下属性,但没有效果:
<item name="subtitleTextColor">@color/color_on_primary</item>
<item name="android:colorControlNormal">@color/color_on_primary</item>
<item name="android:textColorSecondary">@color/color_on_primary</item>
Run Code Online (Sandbox Code Playgroud)
我在 theme.xml 中的顶级主题:
<style name="NITrafficTheme.DayNight" parent="Base.NITrafficTheme"/>
<style name="Base.NITrafficTheme" parent="Base.MaterialThemeBuilder">
<!--Material color attributes -->
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryVariant">@color/color_primary_variant</item>
<item name="colorSecondary">@color/color_secondary</item>
<item name="colorSecondaryVariant">@color/color_secondary_variant</item>
<item name="android:colorBackground">@color/color_background</item>
<item name="colorSurface">@color/color_surface</item>
<item name="colorError">@color/color_error</item>
<item name="colorOnPrimary">@color/color_on_primary</item>
<item name="colorOnSecondary">@color/color_on_secondary</item>
<item name="colorOnBackground">@color/color_on_background</item>
<item name="colorOnSurface">@color/color_on_surface</item>
<item name="colorOnError">@color/color_on_error</item>
....
<!--Component styles-->
<item name="materialAlertDialogTheme">@style/ThemeOverlay.MaterialComponents.Dialog.Alert</item>
<item name="bottomSheetDialogTheme">@style/NITraffic.BottomSheetDialog</item>
<item name="toolbarStyle">@style/NITraffic.Toolbar</item>
<item name="bottomNavigationStyle">@style/NITraffic.BottomNavigation</item>
</style>
<style name="Base.MaterialThemeBuilder" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:statusBarColor">?colorPrimary</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">false</item>
<item name="android:navigationBarColor">?colorPrimary</item>
<item name="android:windowLightNavigationBar" tools:ignore="NewApi">false</item>
<item name="android:navigationBarDividerColor" tools:ignore="NewApi">?colorPrimary</item> …Run Code Online (Sandbox Code Playgroud) xml android android-theme android-styles material-components-android
如何在 AlertDialog.Only AlertDialog 中显示项目,没有任何项目我正在尝试下面的代码,但这似乎不起作用:
CharSequence[] choices = {"Choice1", "Choice2", "Choice3"};
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context)
.setTitle(context.getString(R.string.title))
.setPositiveButton(context.getString(R.string.Ok), null)
.setNeutralButton(context.getString(R.string.Cancel), null)
.setSingleChoiceItems(choices, 1, null);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
Run Code Online (Sandbox Code Playgroud)
我正在使用材料组件样式:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
Run Code Online (Sandbox Code Playgroud)
android android-alertdialog material-design material-components material-components-android
我是android初学者。我想更改弹出菜单背景颜色。我尝试使用此代码更改背景颜色,但它对我不起作用。我不知道为什么不使用此代码。
<!--popup menu item style-->
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.MaterialComponents.Light">
<item name="android:textColor">@color/colorWhite</item>
<item name="android:popupBackground">@color/colorBlack</item>
<item name="actionOverflowMenuStyle">@style/CMOptionsMenu</item>
<item name="android:divider">@color/colorWhite</item>
<item name="android:dividerHeight">1dp</item>
</style>
<style name="CMOptionsMenu" parent="Widget.AppCompat.PopupMenu.Overflow">
<item name="android:popupBackground">@color/colorBlack</item>
<item name="overlapAnchor">false</item>
<item name="android:divider">@color/colorRegisterHeader</item>
<item name="android:dividerHeight">1dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
//此活动代码用于弹出菜单
PopupMenu popup = new PopupMenu(HomeActivity.this, v);
popup.setOnMenuItemClickListener(HomeActivity.this);
popup.inflate(R.menu.popup_menu);
Run Code Online (Sandbox Code Playgroud) android material-design android-toolbar material-components material-components-android
我正在使用导航抽屉,这没有错误
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
Run Code Online (Sandbox Code Playgroud)
但是在androidx中更新后
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.appcompat:design:1.1.0'
Run Code Online (Sandbox Code Playgroud)
此代码不适用于导航抽屉。
我的问题是这种情况下的依赖是什么。请帮忙。
android android-appcompat android-support-library material-components-android androidx
我正在使用密码切换来显示和隐藏密码。而且我不想使用自定义 drawable。但是,当此编辑文本生成错误时,它会覆盖切换密码图标,并且无法向该图标添加填充或边距。如果对此有任何解决方案,那将是一种乐趣。这是我正在使用的代码:
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:textColorHint="@color/white"
app:passwordToggleEnabled="true"
app:passwordToggleTint="@color/white">
<EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
android:hint="@string/password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:maxLength="40"
android:maxLines="1"
android:textColor="@color/white"
android:textColorHint="@color/app_green_color" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud) android android-textinputlayout android-textinputedittext material-components material-components-android
我正在android中创建一个要求性别的表单。为了获得这个输入,我使用了包含两个按钮的 Material Button Toggle Group。我不知道如何知道在我的 activity.java 中点击了哪个按钮。如何了解我的活动中选定的按钮,以便我可以将详细信息保存在不同的数据库中。
xml文件
<com.google.android.material.button.MaterialButtonToggleGroup
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:singleSelection="true">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:layout_marginStart="5dp"
style="?attr/materialButtonOutlinedStyle"/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:layout_marginStart="10dp"
style="?attr/materialButtonOutlinedStyle"/>
</com.google.android.material.button.MaterialButtonToggleGroup>
Run Code Online (Sandbox Code Playgroud)
我的活动.java
MaterialButtonToggleGroup toggleButton = findViewById(R.id.toggleButton);
toggleButton.addOnButtonCheckedListener();
// I CAN'T FIND ANY PROPER SOLUTION
Run Code Online (Sandbox Code Playgroud) java android android-layout android-button material-components-android
如何单击每个 TextInputEditText 的 drawableRight 编辑图像?我想单击编辑图标,然后启用编辑每个字段。我怎样才能做到这一点?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!--First name-->
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="@dimen/_64dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etFirstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:drawableRight="@drawable/icon_edit"
android:hint="@string/label_fname"
android:inputType="textCapWords" />
</com.google.android.material.textfield.TextInputLayout>
<!--Middle name-->
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_registration_tiMiddleName"
android:layout_width="match_parent"
android:layout_height="@dimen/_64dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/etMiddleName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:drawableRight="@drawable/icon_edit"
android:hint="@string/label_mname"
android:inputType="textCapWords"/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
那么如何使用 drawbleRight 单独编辑每个字段。请帮忙。
android onclicklistener android-textinputlayout android-textinputedittext material-components-android
为什么我的警报对话框不适应我手机的暗模式?在我的手机中激活暗模式时,几乎看不到两个按钮的文本,而标题和消息颜色则相反。为什么按钮颜色也不反转?该图标在非深色模式下也不能很好地显示。如何解决所有这些问题?
val builder = AlertDialog.Builder(this)
builder.setTitle(getString(R.string.title))
builder.setMessage(getString(R.string.message))
builder.setPositiveButton(getString(R.string.positive)) { dialog, which ->
Toast.makeText(applicationContext, getString(R.string.pos_toast), Toast.LENGTH_LONG).show()
}
builder.setNegativeButton(getString(R.string.negative)) { dialog, which ->
Toast.makeText(applicationContext, getString(R.string.negative_toast), Toast.LENGTH_LONG).show()
}
builder.setIcon(android.R.drawable.ic_dialog_alert)
builder.show()
Run Code Online (Sandbox Code Playgroud)
我的 stiles.xml:
<resources>
<!-- Base application theme. -->
<style name="MyTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<style name="generalnotitle" parent="MyTheme">
<item name="android:windowNoTitle">true</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud) android android-theme android-alertdialog kotlin material-components-android
有很多 SO 线程说他们的按钮显示为一个错误的正方形
带有 Android 设计库的 Square FloatingActionButton
但是我的目标是使用方形按钮。怎么circle floating action button改成方形的?
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/standardBlue"
app:srcCompat="@drawable/ic_3d_model"/>
Run Code Online (Sandbox Code Playgroud) android floating-action-button android-shapedrawable material-components material-components-android
我有这个问题,在xxx是紫色的光标后,我想知道那个放置光标的名称,我想更改颜色以匹配我的主题。我阅读了许多论坛和文档,唯一找到的是 cursorDrawable,但事实并非如此。请帮我搜索正确的名称或解决方案。谢谢 PD:那东西的紫罗兰色不是我的风格或颜色。
android android-theme android-styles android-textinputlayout material-components-android