我正在尝试ColorStateList使用这个以编程方式创建:
ColorStateList stateList = new ColorStateList(states, colors);
Run Code Online (Sandbox Code Playgroud)
但我不确定这两个参数是什么.
根据文件:
Run Code Online (Sandbox Code Playgroud)public ColorStateList (int[][] states, int[] colors)在API级别1中添加
创建一个ColorStateList,它返回从状态到颜色的指定映射.
有人可以解释一下如何创建这个吗?
状态二维数组的含义是什么?
Google是否已经为这个新的循环FAB按钮发布了已定义的样式或组件,还是应该自行实现该设计?
按钮在此处描述:Google Design | 浮动动作按钮
编辑(05/2015):检查Lukas的回答/Gabriele的答案显示了使用设计支持库实现它的简单方法.
java android material-design android-5.0-lollipop android-design-library
如何在运行时更改活动中的FAB图标.我有这个代码 - >
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fabMainActivity);
Run Code Online (Sandbox Code Playgroud)
我知道这是可能的使用,fab.setBackgroundDrawable();但我是Android的新手,不明白该怎么做.
任何帮助将受到高度赞赏.
谢谢
我想知道如何更改支持库22.2.0中的浮动操作按钮颜色?我试过了
button.setBackgroundColor(color);
Run Code Online (Sandbox Code Playgroud)
但显然,这会改变按钮的可绘制性并变为正方形.
现在我想知道如何改变颜色而不仅仅是颜色,而不会触及形状?
提前致谢
fab.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(PrivateDealActivity.this, R.color.colorWhite)));
Run Code Online (Sandbox Code Playgroud)
这是行不通的。如何更改浮动操作按钮的背景颜色
android material-design floating-action-button material-components material-components-android
我试图在fab的其他项目中实现浮动操作按钮并自定义它,它工作正常.但这次,当我在xml布局中创建fab对象时,它显示错误.感到困惑,它试图删除它的一些标签,并发现给出android:backgroundTint标签是错误出现的时候.
这是代码:
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="mini"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_action_fab"
android:backgroundTint="#2196F3"
android:layout_margin="12dp"/>
Run Code Online (Sandbox Code Playgroud)
这是我的构建:
compileSdkVersion 25
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "com.xxxx.xxxx"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "2.0.4"
}
Run Code Online (Sandbox Code Playgroud)
我还添加了谷歌设计gradle.
错误:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.xxxx.xxxx/com.xxxx.xxxx.HomeActivity}: android.view.InflateException: Binary XML file line #141: Binary XML file line #141: Error inflating class android.support.design.widget.FloatingActionButton
Run Code Online (Sandbox Code Playgroud)
一旦我删除android:backgroundtint标记,错误就消失了.知道为什么会这样吗?