我正在实现底部导航菜单。但未选择菜单中的第一项。我注意到,当我更改栏背景的颜色时,它会显示出来,原因是第一个项目“启用”颜色与导航栏的背景颜色相同。如何更改已启用选项卡以及其余项目的颜色。默认情况下它们是黑色的......假设我想将它们更改为白色。感谢主要活动的图片。http://pctechtips.org/apps/activity.png 菜单 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/navigation_home"
android:icon="@drawable/ic_home_black_24dp"
android:title="@string/title_home" />
<item
android:id="@+id/navigation_dashboard"
android:icon="@drawable/ic_dashboard_black_24dp"
android:title="@string/title_dashboard" />
<item
android:id="@+id/navigation_notifications"
android:icon="@drawable/ic_notifications_black_24dp"
android:title="@string/title_notifications" />
</menu>
Run Code Online (Sandbox Code Playgroud)
活动主文件
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MainActivity">
<org.techgeorge.textrecon.PaintView
android:id="@+id/paintView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:background="@color/colorPrimary"
app:menu="@menu/bottom_nav_menu" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) android bottomnavigationview android-bottomnav material-components material-components-android
我的自定义复选框 ( MyCheckbox) 已从 扩展androidx.appcompat.widget.AppCompatCheckBox,但默认样式不适用于它。
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="android:checkboxStyle">@style/CheckboxTheme</item>
<item name="checkboxStyle">@style/CheckboxTheme</item>
</style>
<style name="CheckboxTheme" parent="@style/Widget.AppCompat.CompoundButton.CheckBox">
<!-- for example try to change background -->
<item name="android:background">@color/colorPrimary</item>
</style>
Run Code Online (Sandbox Code Playgroud)
但在预览和运行时没有改变任何东西。
另外,我迁移了 MaterialComponent (从 扩展com.google.android.material.checkbox.MaterialCheckBox)版本:
com.google.android.material:material:1.1.0-beta01
Run Code Online (Sandbox Code Playgroud)
并用于@style/Widget.MaterialComponents.CompoundButton.CheckBox样式。但没有改变。
注意: 当我提到每个实例的样式时,此问题就修复了:
<com.something.MyCheckBox
android:id="@+id/ch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="some thing"
style="@style/CheckboxTheme"
/>
Run Code Online (Sandbox Code Playgroud)
但我想为此类的所有实例设置此样式。 你可以帮帮我吗?
android android-custom-view material-components material-components-android androidx
我正在尝试实现BottomAppBar我将在何处处理WebView.
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<com.google.android.material.bottomappbar.BottomAppBar
android:id="@+id/bottom_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:layout_behavior="com.google.android.material.bottomappbar.BottomAppBar$Behavior"
app:hideOnScroll="true"
app:fabAttached="true"
app:fabAlignmentMode="end"
app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_share"
android:tint="#fff"
app:layout_anchor="@id/bottom_bar"
app:backgroundTint="@color/colorPrimary"/>
Run Code Online (Sandbox Code Playgroud)
一切正常,但我希望能够显示和隐藏BottomAppBar用户分别向下和向上滚动的时间,就像这里的行为一样。
我在任何地方都找不到关于它的教程,所以有人在上面实施了解决方案吗?
我正在尝试使用 MaterialComponents 中的 MDCRaisedButton,将其添加为与所有其他依赖项类似的 pod 依赖项,但是当我尝试导入它时,出现编译错误 Module MaterialComponents not found
使用这个 pod 需要采取什么额外的步骤吗?
我在他们使用的演示中注意到
pod 'MaterialComponents/Typography', :path => '../../'
Run Code Online (Sandbox Code Playgroud)
路径有什么作用?当我尝试运行 pod update 时出现错误
我正在使用 iOS 的材料组件来制作可拖动的底部工作表,它从半屏(预览模式)开始,您可以拖动到全屏。但我不知道如何,而且文档也不是很完整。https://material.io/develop/ios/components/bottom-sheet/
我在 MDCBottomSheetController 中展示了我的 DetailViewController:
let graphDetailViewController = UIStoryboard.detail().instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
let bottomSheet: MDCBottomSheetController = MDCBottomSheetController(contentViewController: graphDetailViewController)
bottomSheet.preferredContentSize = CGSize(width: self.view.frame.size.width, height: self.view.frame.size.height / 2)
present(bottomSheet, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)
使用此代码,我的 vc 显示为半屏,但无法将其拖至全屏。
有没有人对 iOS 的材料组件(底页)有经验并且可以帮助我?
非常感谢!
swift bottom-sheet material-components material-components-ios
我正在尝试BottomNavigationView使用此库将其添加到布局中:
implementation 'com.google.android.material:material:1.0.0'
Run Code Online (Sandbox Code Playgroud)
这是我的布局:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".home.HomeActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme" />
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:itemBackground="?colorPrimary"
app:itemIconTint="@drawable/bottom_navigation_selector"
app:itemTextColor="@drawable/bottom_navigation_selector"
app:layout_insetEdge="bottom"
app:layout_behavior="@string/hide_bottom_view_on_scroll_behavior"
app:menu="@menu/bottom_navigation" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/add_model"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:fabSize="normal"
app:layout_anchor="@id/bottom_navigation"
app:layout_anchorGravity="end"
app:srcCompat="@drawable/ic_add_white_24dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
它在模拟器上运行,但是当我想在真实设备上启动应用程序时,出现以下错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rightechco.rayanpairpanel/com.rightechco.rayanpairpanel.home.HomeActivity}: android.view.InflateException: Binary XML file line #23: Error inflating class com.google.android.material.bottomnavigation.BottomNavigationView
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2489)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2551)
at android.app.ActivityThread.access$1000(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1432)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194) …Run Code Online (Sandbox Code Playgroud) 我想简单地将样式应用到这样的主题级别上的所有按钮
<style name="BaseTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
...
<item name="buttonStyle">@style/DefaultButton</item>
</style>
<style name="DefaultButton" parent="Widget.MaterialComponents.Button">
<item name="android:textColor">@color/whatever</item>
</style>
<Button
android:id="@+id/addChannelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:layout_margin="16dp"
android:text="Add room" />
Run Code Online (Sandbox Code Playgroud)
为什么这不起作用?它会在 appcompat
// 如果我使用Theme.MaterialComponents.Light.NoActionBar.Bridge,那么它有效
android android-button material-design material-components material-components-android
我有一个错误'Theme.MaterialComponents.Light.NoActionBar'的styles.xml(在'Theme.MaterialComponents.Light.NoActionBar'经过多次gradle这个更新是因为错误的红色)。我的组件也没有按照我的设计思路很好地排列。
我已经清理并重建项目,使缓存无效/重新启动,更新 gradle(可能不是正确答案)并且没有答案。我只是想也许我是唯一一个遇到这个问题的人,也许是因为我的初级问题:')
样式文件
`
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/hitam</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
Run Code Online (Sandbox Code Playgroud)
`
项目梯度
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Run Code Online (Sandbox Code Playgroud)
'
应用程序渐变
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 29
defaultConfig {
applicationId "blablabla" …Run Code Online (Sandbox Code Playgroud) java android material-components material-components-android androidx
我正在制作一个聊天应用程序,我想在 editText 中放置一个按钮以启用媒体文件的发送。我不知道该怎么做。
试图使 editText 中的矢量资产可点击,但它不会
java android material-design material-components material-components-android
令我惊讶的是,如果 Snackbar 跨越多行,它本身似乎会在 TextView 上设置额外的填充。它有效地将 Snackbar 的高度加倍,并且由于某种原因只影响垂直填充。我在SnackbarContentLayout.onMeasure:
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (mMaxWidth > 0 && getMeasuredWidth() > mMaxWidth) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxWidth, MeasureSpec.EXACTLY);
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
final int multiLineVPadding = getResources().getDimensionPixelSize(
R.dimen.design_snackbar_padding_vertical_2lines);
final int singleLineVPadding = getResources().getDimensionPixelSize(
R.dimen.design_snackbar_padding_vertical);
final boolean isMultiLine = mMessageView.getLayout().getLineCount() > 1;
boolean remeasure = false;
if (isMultiLine && mMaxInlineActionWidth > 0
&& mActionView.getMeasuredWidth() > mMaxInlineActionWidth) {
if (updateViewsWithinLayout(VERTICAL, multiLineVPadding,
multiLineVPadding - singleLineVPadding)) {
remeasure = true;
}
} else {
final int messagePadding = isMultiLine …Run Code Online (Sandbox Code Playgroud) android snackbar android-snackbar material-components material-components-android
android ×8
material-components-android ×6
androidx ×2
java ×2
bottom-sheet ×1
ios ×1
snackbar ×1
swift ×1