无法使用任何解决方案以编程方式更改晶圆厂颜色
Not working any solution to change a fab color programmatically
我必须将单击时的 fab 颜色从蓝色更改为橙色。我自己尝试过,但没有用,所以我在堆栈中搜索了答案,发现了他们提出的一些解决方案,但对我不起作用。
我遇到的其中一个问题是 :
所以我尝试使用:
fab.setBackgroundColor(Color.parseColor("#ffffff"));
fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#33691E"));
mFab.setBackgroundTintList(ColorStateList.valueOf(getResources.getColor(R.color.mColor)));
private void onClickStart(View v) {
int colorArancione = getResources().getColor(R.color.Arancione);
if(mStatoScanButton) {
mProgressBar.setVisibility(View.VISIBLE);
mScanButton.setColorFilter(colorArancione);
mScanButton.setImageDrawable(getDrawable(R.drawable.ic_add));
//mScanButton.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Arancione)));
mStatoScanButton=false;
startTimedScan();
}else if(!mStatoScanButton){
mProgressBar.setVisibility(View.GONE);
mScanButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Blue)));
mStatoScanButton=true;
if(bluetoothDevicesScansionati.size() == 0)
mTestoTextView = "Nessun dispositivo trovato";
fragment_dispositiviScansionati.updateTexto();
try {
mTio.stopScan();
} catch (InvalidObjectException e) {
e.printStackTrace();
}
}
}
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickStart"
android:backgroundTint="@color/Blue"
android:src="@drawable/ic_search_black_24dp"
android:fontFamily="@font/lustria"
android:elevation="2dp"
android:layout_gravity="center"
app:maxImageSize="35dp"
app:fabCustomSize="70dp"
app:borderWidth="0dp"
/>
文档建议默认使用@color/accent。但是我们可以使用
在代码上覆盖它
fab.setBackgroundTintList(ColorStateList)
但请记住,
使用此库的最低 API 版本为 15,因此您需要更新它!如果你不想这样做
在您的 xml 文件中,您应该使用 属性 app:backgroundTint="@color/Blue" 而不是 android:backgroundTint="@color/Blue”像这样:
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickStart"
app:backgroundTint="@color/Blue"
android:src="@drawable/ic_search_black_24dp"
android:fontFamily="@font/lustria"
android:elevation="2dp"
android:layout_gravity="center"
app:maxImageSize="35dp"
app:fabCustomSize="70dp"
app:borderWidth="0dp"
/>
然后你可以使用这个方法:
fab.setBackgroundTintList(ColorStateList.valueOf(#33691E)));
因为此方法不适用于 属性 "android:"
我必须将单击时的 fab 颜色从蓝色更改为橙色。我自己尝试过,但没有用,所以我在堆栈中搜索了答案,发现了他们提出的一些解决方案,但对我不起作用。
我遇到的其中一个问题是
所以我尝试使用:
fab.setBackgroundColor(Color.parseColor("#ffffff"));
fab.setBackgroundTintList(ColorStateList.valueOf(Color.parseColor("#33691E"));
mFab.setBackgroundTintList(ColorStateList.valueOf(getResources.getColor(R.color.mColor)));
private void onClickStart(View v) {
int colorArancione = getResources().getColor(R.color.Arancione);
if(mStatoScanButton) {
mProgressBar.setVisibility(View.VISIBLE);
mScanButton.setColorFilter(colorArancione);
mScanButton.setImageDrawable(getDrawable(R.drawable.ic_add));
//mScanButton.setForegroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Arancione)));
mStatoScanButton=false;
startTimedScan();
}else if(!mStatoScanButton){
mProgressBar.setVisibility(View.GONE);
mScanButton.setBackgroundTintList(ColorStateList.valueOf(getResources().getColor(R.color.Blue)));
mStatoScanButton=true;
if(bluetoothDevicesScansionati.size() == 0)
mTestoTextView = "Nessun dispositivo trovato";
fragment_dispositiviScansionati.updateTexto();
try {
mTio.stopScan();
} catch (InvalidObjectException e) {
e.printStackTrace();
}
}
}
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickStart"
android:backgroundTint="@color/Blue"
android:src="@drawable/ic_search_black_24dp"
android:fontFamily="@font/lustria"
android:elevation="2dp"
android:layout_gravity="center"
app:maxImageSize="35dp"
app:fabCustomSize="70dp"
app:borderWidth="0dp"
/>
文档建议默认使用@color/accent。但是我们可以使用
在代码上覆盖它fab.setBackgroundTintList(ColorStateList)
但请记住,
使用此库的最低 API 版本为 15,因此您需要更新它!如果你不想这样做
在您的 xml 文件中,您应该使用 属性 app:backgroundTint="@color/Blue" 而不是 android:backgroundTint="@color/Blue”像这样:
<android.support.design.widget.FloatingActionButton
android:id="@+id/scanButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onClickStart"
app:backgroundTint="@color/Blue"
android:src="@drawable/ic_search_black_24dp"
android:fontFamily="@font/lustria"
android:elevation="2dp"
android:layout_gravity="center"
app:maxImageSize="35dp"
app:fabCustomSize="70dp"
app:borderWidth="0dp"
/>
然后你可以使用这个方法:
fab.setBackgroundTintList(ColorStateList.valueOf(#33691E)));
因为此方法不适用于 属性 "android:"