How to use CardView getCardBackgroundColor correctly - android-cardview

I am trying to compare CardView background color with color from my global colors (from colors.xml).
if (cardView1.getCardBackgroundColor() == ContextCompat.getColor(getApplication(), R.color.grayLighter))
cardView1.getCardBackgroundColor return ColorStateList and not int,
and I cant use getCardBackgroundColor().getDefaultColor() because the button don't have the default color.
Thank you for your help

Related

How to overwrite the accent color (within the code) in a macOS SwiftUI application?

I'm writing an application where I want there to be a default color and the user can then overwritten it with their own choice. This works in iOS but I realized the macOS version won't let me overwrite the accent color.
To demo this I created a mini project and set the asset to pink so it would be obvious what the accent color is (noticed if I don't do this it just stays default blue)
I then added a simple list to the main ContentView so I could see the accent color. My code is:
struct ContentView: View {
let myListitems = [
"one", "two", "another", "and more"
]
#State var selectedItem:String?
var body: some View {
VStack {
Text("Hello, world!")
.padding()
List(myListitems, id: \.self, selection: $selectedItem) { item in
Text(item)
}
}
}
}
I then tried to set the accent color to blue on the main WindowGroup part AND (separately) on the ContentView page. Neither affect the pink accent.
Images to show the code changes:
Is there any way that you know of to overwrite this accent color (whether blue or user-defined in assets)? I would love the user to be able to change the color for the entire app but right now can't see how to even affect a view.
Thanks for any help
Users can do that in system preferences by changing accent color and highlight color, multicolor means use the color defined by the apps, other colors mean use that in every app. You don't need to do anything, it works out of the box.
You can reference those colors by NSColor.controlAccentColor and NSColor.selectedContentBackgroundColor if you need them for custom UI elements. As far as I know, SwiftUI only has Color.accentColor out of the box but you can instantiate Color with an NSColor object.

Mapbox-gl-draw change drawing style after click a button

I am trying to let the user choose their paint color and then paint polygon on map. I know there is a setFeatureProperty method, but it needs to pass in a feature ID and thus user will need to draw the shape first and then change style. Is there anyway to just change to draw style programmably for future drawing? Any help is appreciated.
Based on the Gist https://gist.github.com/dnseminara/0790e53cef9867e848e716937727ab18
It's possible to get feature ID:
// callback for draw.update and draw.selectionchange
var setDrawFeature = function(e) {
if (e.features.length && e.features[0].type === 'Feature') {
var feat = e.features[0];
drawFeatureID = feat.id;
}
}
I've made this Jsfidle: https://jsfiddle.net/ToniBCN/y79ajgrw/3/ Maybe it could help you because it's easy to change feature color before draw and not after like the example.

Color and Colors class in Flutter

I was working with Colors class in Flutter.
Added a buildkey function with input "Color zinc" and the same takes the value like Colors.red, Colors purple etc.
However, if I add the input as "Colors Zinc" the values like Colors.red, Colors.purple throws an error. Why this is so?
The class Colors should match the input class (Colors in this case) I think?enter image description here
It would be helpful if you could attach a screenshot or maybe paste the exact error that you are getting.
But meanwhile as I understood it, It seems like that you are telling this works fine for you:
Expanded buildkey(Color zinc, int buildnumber) { ... }
But you are getting some error with this:
Expanded buildkey(Colors zinc, int buildnumber) { ... }
Which is correct behaviour as Colors.[color] returns a swatch constant which is of type color.
e.g: Color selection = Colors.green[400];
For more info: https://api.flutter.dev/flutter/material/Colors-class.html
May be I found the solution of my issue..
When i looked into the dart file of colors class. I found that,
Colors.green is actually an object of Color class. Code is something like this
Class Colors
Color green = Color(....);
Might be that is the reason thats why it requires it requires color class while initilization of variable and not Colors.

GtkCellRendererToggle - color of toggle button inside treeview

I have a treeview that uses GtkCellRendererToggle to display toggle buttons inside cells. My question: Is is possible to set the color just for the toggle button there? I only know how to set the cell background, which is done like this:
g_object_set (toggle-renderer, "cell-background",
"anycolouryoulike", "cell-background-set", TRUE, NULL);
GtkCellRenderer features only cell background properties, I wonder if there is nethertheless a way to do it? (I use C, but if there is a way, an example in any language would do).
GtkCssProvider might help, just try to style buttons within GtkCssProvider (list of suported properties per widget , not necessary for this case)
You could use something like
#supercolorme {
color: #ffed00;
}
and name your widgets supercolorme by using
void gtk_widget_set_name (GtkWidget *widget, const gchar *name); as described in the gtk+ API docs

Gtk Button inner-border

I add a button to HBox, with expand equal to False, but I want the button to have more spacing between its label and border. I assume it is "inner-border" property, but it is read-only. How can I set it to e.g. 4px?
gtk.Label is a subclass of gtk.Misc which has the method set_padding. If you get the label out of the gtk.Button then you can just call set_padding on it.
You could do something like:
label = gtk.Label("Hello World")
button = gtk.Button()
/* Add 10 pixels border around the label */
label.set_padding(10, 10)
/* Add the label to the button */
button.add(label)
/* Show the label as the button will assume it is already shown */
label.show()
Wrong answer:
What you're looking for is called "padding". When you add your button to the container, for example by calling gtk.Box.pack_start, just set the padding parameter to a positive integer.
Update:
Seems I misread the question. In that case, my guess is that you're supposed to use gtk_widget_modify_style, as inner-border is a style property. You'll first get the style modifier you need by calling gtk_widget_get_modifier_style. You'll then be able to modify the style only for that button using the ressource styles matching rules.
you can use "inner-border" style property of gtk button.
here, small code snippets
In gtkrc file:
style "button_style"
{
GtkButton::inner-border = {10,10,10,10}
}
class "GtkButton" style "button_style"
In .py file:
gtk.rc_parse(rc_file_path + rc_file)
[Edit]
In gtkrc file:
style "button_style"
{
GtkButton::inner-border = {10,10,10,10}
}
widget "*.StyleButton" style "button_style" # apply style for specific name of widget
In .py file:
gtk.rc_parse(rc_file_path + rc_file)
#set name of button
self.style_button.set_name('StyleButton')
hope, it would be helpful.
I sometimes just add spaces in the label !
gtk.Button(" Label ")
to get some spacing.
Hope this could help you.