Change Cuboid circle button color on runtime - android

Cuboid circle button is a custom circle button in android (source: Github Cuboid Circle Button).
I'm using that button in my app. It works well, but I cannot find a way to change its color programmatically on runtime.
In the class, before onCreate I have:
com.cuboid.cuboidcirclebutton.CuboidButton btnReplayEnd;
Then in onCreate:
btnReplayEnd = (com.cuboid.cuboidcirclebutton.CuboidButton) findViewById(R.id.btnReplayEnd);
And in the 'setTheme' method (in the same class):
btnReplayEnd.setCircle_color(getResources().getColor(R.color‌.replayNormalDark));

there is no way to change the circler color of com.cuboid.cuboidcirclebutton.CuboidButton programatically you can only change it via xml using app:cub_color="#color/color_03A9F4"
like this
<com.cuboid.cuboidcirclebutton.CuboidButton
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:text="No Border"
android:textColor="#000000"
android:textSize="18sp"
app:cub_border_radius="0dp"
app:cub_color="#color/color_03A9F4"
app:cub_fontstyle="fonts/Bellerose.ttf"
app:cub_hover_color="#00BFFF1"
/>

Related

Make a button with custom icon on Android

I'm developing an android app and want to add a button (widget?) with icon.
As i understand, it's appearance should be described in xml resources.
I can do it in java code, but it seems incorrect.
public class VideoButton extends android.support.v7.widget.AppCompatButton {
private void onCreate(){
setBackground(ResourceManager.getDrawable(R.mipmap.roundbackgroundnormal));
Drawable icon = ResourceManager.getDrawable(R.mipmap.video);
icon.setBounds(6,0,50,44);
setCompoundDrawables(icon,null,null,null);
setPadding(12,8,8,8);
...
So, i wrote an xml replacement code that doesn't fit my expectations
<blah.blah.blah.ui.widgets.VideoButton
android:id="#+id/record"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#mipmap/roundbackgroundnormal"
android:drawableStart="#drawable/video"
android:visibility="visible" />
I expect this (ty java),
but get this
How to fix my xml code to get a proper result?
TY, if possible fix terminology.
Better to use FloatingActionButton
Floating action buttons are used for a special type of promoted action. They are distinguished by a circled icon floating above the UI and have special motion behaviors related to morphing, launching, and the transferring anchor point.
Compile this dependencies
compile 'com.android.support:design:27.0.2'
SAMPLE CODE
<android.support.design.widget.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/ic_check_box_black_24dp" />
RESULT
OR
You can use ImageButton
Displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by the setImageResource(int) method.
SAMPLE CODE
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_check_box_black_24dp" />
OUTPUT
<blah.blah.blah.ui.widgets.ViseoButton
android:id="#+id/record"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#mipmap/roundbackgroundnormal"
android:drawableStart="#drawable/video"
android:visibility="visible" />
You can design with your custom icon.png and move it into your project folder
mipmap
android:background="#mipmap/roundbackgroundnormal"

Android Button changing color and incrementing size

Hi guys im new in android stuff and i have a problem with a button when color change, because when it changes the button grows a bit and i dont know why. My code of the button click is below.
produzirbt.setBackgroundColor(Color.rgb(38, 198, 219));
Toast.makeText(getApplicationContext(), "Avaria iniciada.", Toast.LENGTH_SHORT).show();
Xml
<Button
android:layout_width="150dp"
android:layout_height="100dp"
android:text="Pausa"
android:id="#+id/Pausa"
android:textSize="50px"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_above="#+id/Avaria"
android:layout_toRightOf="#+id/terminaliniciado"
android:layout_toEndOf="#+id/terminaliniciado" />
In order to keep button size use setColorFilter() method.
In your case:
produzirbt.getBackground().setColorFilter(ContextCompat.getColor(this, R.color.your_color), PorterDuff.Mode.SRC_ATOP);
Your button by default has a backgrond definded by some xml file. It contains backround color, corner radiuses and padding. Then in java code you change this style to plain color and padding becomes zero. To prevent size changing you should define base background with a color. Like this:
<Button
android:layout_width="150dp"
android:layout_height="100dp"
android:text="Pausa"
android:id="#+id/Pausa"
android:textSize="32sp"
android:background="#color/my_button_color"
android:layout_above="#+id/Avaria"
android:layout_toRightOf="#+id/terminaliniciado"
android:layout_toEndOf="#+id/terminaliniciado" />
A the same time using color for button is a hacky method. It'll be better to define normal style as the documentation says.

Android: button with a part of it having a background

In android is there a mechanism by which a part of the button can have a background picture.
What I need is something like shown in the picture below (A white button which match the parent's width with a picture taking a part of the button)
In your Button XML
android:drawableLeft="#drawable/yourimage"
You can set background to whole button but if you want to show icon like above, then there is drawableLeft,drawableTo,drawableBottom,drawableRight properties in xml.
<Button
...
...
android:drawableLeft="#drawable/your_drawable" />
you need to use :
XML :
<Button android:id="#+id/btn_confirm"
android:text="#string/confirm_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="15dip"
android:drawableLeft="#drawable/left_icon"
android:drawablePadding="2dip"
android:gravity="center" />
Java Code :
btnRegisterMa.setCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable); // can be null
// Or
btnRegisterMa.setCompoundDrawablesWithIntrinsicBounds(R.drawable.left_icon, R.drawable.topt_icon, R.drawable.right_icon, R.drawable.botton_icon); // use zero to null
// Drawable Padding
btnRegisterMa.setCompoundDrawablePadding(drawable_padding_intm);

Change ToggleButton background to Clear/Dark Gray

I'm using two toggle buttons on my application, when I run it on the emulator the button has black text, and a light gray background. As we can see in the next image:
When I run it on my real device the button has another style, it has white text, and a black background. As shown in the next image.
My QUESTION IS: How to change the style of a ToggleButton to it always stay with a clear gray background, as in the first image? Is it defined by a Theme?
The xml code used for the button was:
<ToggleButton
android:id="#+id/toggleButtonSimulado"
android:layout_gravity="center|top"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="On"
android:textOff="Off" />
Style of the button or any other view changes in the real device according to the current theme selected on that device. To prevent this you need to specify background color and text color explicitly. Use a gradient as the background of the button. For example:
<ToggleButton
android:id="#+id/toggleButtonSimulado"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/gray_gradient"
android:textOn="On"
android:textOff="Off"
android:textColor="#android:color/black" />
You can use your own backgrounds for the buttons.
Search btn_toggle_off.9.png/btn_toggle_on.9 on your sdk install dir(android-sdk-mac_86/platforms/android-9/data/res/drawable-hdpi).
And make sure to copy the selector located on drawable folder
Or you can try:
androiddrawables
androiddrawablesexplorer
Hope this help.

How to make a button non-transparent in Android?

when I just use the normal default button in android, depending on what colour the background of the intent is the colour of the button changes slightly to the colour of the background. I want it so that the button is fully opaque (like when the intent has a white background), how do I do this? thanks.
[it might only do it in android 3.1]
the same button on different backgrounds
You can set the background for a button to any drawable. In XML, do it using the android:background attribute:
<Button
. . .
android:background="#drawable/my_button_bg"
. . .
/>
In code, use the setBackgroundResource method:
Button button = (Button) findViewById(R.id.my_button);
button.setBackgroundResource(R.drawable.my_button_bg);
Your background drawable can be a State List drawable, which you can use to change the background appearance when the button is pressed, has focus, etc.
<Button android:background="#android:color/transparent"
android:text="#+id/Button01"
android:id="#+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff" />
By using android:background="#android:color/transparent" the button background will become transparent

Categories

Resources