How to get hosting Activity from a view?

I have an Activity with 3 EditTexts and a custom view which acts a specialised keyboard to add information into the EditTexts. Currently I’m passing the Activity into the view so that I can get the currently focused edit text and update the contents from the custom keyboard. Is there a way of referencing the … Read more

Same-named attributes in attrs.xml for custom view

I’m writing a few custom views which share some same-named attributes. In their respective <declare-styleable> section in attrs.xml I’d like to use the same names for attributes: <?xml version=”1.0″ encoding=”utf-8″?> <resources> <declare-styleable name=”MyView1″> <attr name=”myattr1″ format=”string” /> <attr name=”myattr2″ format=”dimension” /> … </declare-styleable> <declare-styleable name=”MyView2″> <attr name=”myattr1″ format=”string” /> <attr name=”myattr2″ format=”dimension” /> … </declare-styleable> … Read more

How to lay out Views in RelativeLayout programmatically?

I’m trying to achieve the following programmatically (rather than declaratively via XML): <RelativeLayout…> <TextView … android:id=”@+id/label1″ /> <TextView … android:id=”@+id/label2″ android:layout_below: “@id/label1” /> </RelativeLayout> In other words, how do I make the second TextView appear below the first one, but I want to do it in code: RelativeLayout layout = new RelativeLayout(this); TextView label1 = … Read more

What does the LayoutInflater attachToRoot parameter mean?

The LayoutInflater.inflate documentation isn’t exactly clear to me about the purpose of the attachToRoot parameter. attachToRoot: whether the inflated hierarchy should be attached to the root parameter? If false, root is only used to create the correct subclass of LayoutParams for the root view in the XML. Could someone please explain in more detail, specifically … Read more

Coloring Buttons in Android with Material Design and AppCompat

Before the AppCompat update came out today I was able to change the color of buttons in Android L but not on older versions. After including the new AppCompat update I am unable to change the color for either version, when I do try the button just disappears. Does anyone know how to change the … Read more