In Android - How can I set a default style for buttons that are created programmatically? - android-widget

My Android application can't use XML buttons, because the size and label of the buttons are created based on user input. Therefore I need to create the buttons in the activity and add them to the layout programmatically.
How can I create a default button style (foreground and background color, padding, font, etc), and apply that style to all of my buttons in the Java code?

One way to do this might be the following:
1) Create a custom button class (wonkyBtn) that extends Button.
2) In wonkyBtn's constructor, instantiate an Android button, and then reconfigure it to your heart's content... If it works out that you need multiple flavors of button, you can overload the constructor, or pass in a parameter.
3) Return a brand, spankin' new wonkyBtn to your application...
I hope I got that right,
R.

Related

How do I make these GTK buttons that are drawn together in a group?

GTK has a way to draw a group of buttons together so they look like one big button with a divider between them, rather than buttons that are drawn apart. It's useful for drawing buttons together that have a similar function.
Here's an example from the GTK inspector, where they appear to be specifically toggle buttons where only one can be selected:
Another example, from Glade, where each button represents a category of widgets and opens a menu:
What is this style of buttons called, and how do I make them?
GTK Inspector example shows GtkStackSwitcher, a special widget used to control the GtkStack (for page switching).
Generally, to achieve this visual effect for a group of buttons, GtkButtonBox is used with the layout style set to GTK_BUTTONBOX_EXPAND.
Buttons expand to fill the box. This entails giving buttons a "linked" appearance, making button sizes homogeneous, and setting spacing to 0
You can also manually add a "linked" style to any container with buttons:
GtkStyleContext *context;
...
context = gtk_widget_get_style_context(button_box);
gtk_style_context_add_class(context, GTK_STYLE_CLASS_LINKED);
HowDoI/Buttons (paragraph "Linked buttons")

Setting Button's Size in TinyMCE 4

I'm new with TinyMCE and trying to set the size of some of the buttons in the editor to small and some others' to medium, in TinyMCE 4.
I know about this property toolbar_items_size but this sets all the button's size small or medium. Instead, I'm trying to set the size property of the buttons in editor.buttons[] manually after the buttons get registered with the editor but before the theme gets initialized since the theme uses Factory.create() to create buttons & that sets class btn-<size> to the button, which sets its size.
I've looked into TinyMCE's code too but have not able to figure out a way to do so. Also, I've observed that all the editor's events get fired after the theme gets initialized, like BeforeSetContent,..etc.
I'm using modern theme.
Is there some way to achieve this?
Thanks.
TinyMCE simply does not support what you are trying to do - the buttons on the toolbar(s) are a uniform size. You can pick that uniform size (as you reference) but you can't mix buttons of different sizes on the toolbar.

How can I customize partstack header in rcp application

I am trying to customize PartStack header of a view in rcp application. My goal is to customize the coloring of the header and to add date and time to it and hide minimize and maximize buttons. Buttons can be hidden using css but other goals give me hard time. At the moment I am looking to use a custom renderer by overriding some methods in StackRenderer class. Is that a right approach or is there another renderer that I shoud use?
If you don't want the min/max buttons then do not include MinMaxAddon in the Add On list in the Application.e4xmi.
Using a custom renderer for StackRenderer is useful for changing the text of the part tabs items. If you want to put text elsewhere on the part stack line you will probably need to look at the MinMaxAddon to see how it does that.

Steps for creating a custom view

How can I create a custom view with a custom style? I have many TextView's in my layout and its kind of difficult to manage all of them. I want to group them in a custom view with custom look (a box with rounded corners) and in my code just give the values to the custom view code to handle it itself.
What I am looking after is something like:
Can someone plesae tell me the steps to create such custom view with rounded box and few TextView's inside it?
Two approaches:
You can create a layout for your view. You need to take different layout widgets like textviews etc. and assign them values.
You can use canvas to draw such view.
The proper way is to inherit from View. Either programatically or in designer You assign any layout to this view. To the layout You assign Your elements ( TextViews, whatever ).
Create methods in the derived View class which fill the inner elements, something like getters/setters, like properties in c#. Those are public.
Then place Your custom compound control onto Your main view.
I for myself created a column orientated tablecontrol with custom scrollbar this way ( but pure via code ) and it works very well. Ah, and additionally You can draw shapes on Your derived view, which allow You relatively simple to apply round corners, and even color transitions.
I'm assuming you're using eclipse to create your android project.
Go to your src file and create a new layout (relative layout works best here). There is a visual representation of the layout you're creating so you should be able to play around with it. Drag and drop the textviews where you want them and give them unique names. Then in your java code, call the textviews like:
TextView text = (TextView) findViewById(R.id.textview_name_here);
text.setText("Your Text Here");
There are plenty of examples online.

Starling Feathers Extend Theme - Custom button

I am trying to work out how to use a sprite added to a themes sprite sheet as a button but not having much luck.
I have created the entire button with click state and label and added to the theme sprite sheet and need to use on a button. I have a number of custom buttons I would like to use but I would also like to use a number of the theme skin (Minimal skin).
I have looked at the extending themes section but unsure how to use a signal sprite image for 1 button, another for another button and the theme skin for others.
Cheers
Look at the names property, this is how the theme "knows" what initializer function to call