I would like to change the color of the floating button and put a small text but I do not know how to do it could help me
I would like to change the color of the floating button and put a small text but I do not know how to do it could help me
Better if you do this programmatically, for example, in any event of your activity you can do:
public class MinhaActivity extends AppCompatActivity {
Button meubotao;
// ...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
meubotao = (Buttom) findViewById(R.id.meubotaonoxml);
// aqui voce pode mudar a cor original, uma imagem, um shape num xml, em fim o que voce quiser
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
meubotao.setBackgroundDrawable(getResources().getDrawable(R.drawable.meufundo) );
} else {
meubotao.setBackground( getResources().getDrawable(R.drawable.meufundo));
}
// especificamente nesse caso, eu verifico a versão do android para evitar problemas
// você pode usar o mesmo recurso em qualquer evento que voce quiser, pois a forma para setar o background de um compnente no android via código é essa
// se voce quiser mudar a cor, basta colocar a cor que voce deseja usando uma referencia no seu "/values/colors.xml" ou mesmo a cor como uma string usando parsecolor:
meubotao.setBackground(getColor(getApplicatioContext(), Color.parseColor("#FFFFFF")));
}
}
Hope it helps
You need to add the backgroundTint line, for example:
<android.support.design.widget.FloatingActionButton
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add"
app:backgroundTint="@color/orange"
app:borderWidth="0dp"
app:elevation="6dp"
app:fabSize="normal" >
Remember that this line does not start with android: and yes with app:
To add text in place of the image, it's a bit more complicated, you need to include it inside a FrameLayout.
Example:
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right">
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:color/transparent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@android:string/ok"
android:elevation="16dp"
android:textColor="@android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium" />
</FrameLayout>