How to create a custom component? - android

I would like to create this component as a custom component in Android:
I shall use it like:
<MyEditText android:layout_width="match_parent"
android:layout_height="wrap_content"
label="ART" />
And like the regular EditText, when focus is on, borders and label become blue, like in the image, when focus is off, label and borders become grey.
Is it possible to create a component as described above?

Related

Which components of Android to use?

I am trying to achieve the list of buttons for "account, privacy, security etc" like in the image. I have tried radio buttons so far but cant set their background color and they do not last from left side to right side. Any suggestions?
You may use buttons, but you need to set the attribute android:layout_width="match_parent" for them to span the whole width of the activity.
<Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Account"/>

Create text field where label is inside text field's borders

I want to create a text field where the label is inside the borders, something like this:
How can I do this with the material components?
I don't want to have the label between the border like this: (doesn't look nice anymore when you have multiple filled fields, it's to nervous with all the interrupted borders in my opinion)
A simple thing you could do is to move the hint into the TextInputEditText and disable it on the TextInputLayout.
Then it behaves like the old EditTexts: The line doesn't get interrupted because the hint disappears when the user starts typing. You could use app:helperText if you need to show text permanently (or maybe put a TextView on top).
There are other ways to get the perfect result, but they seem "hacky". Like this and this.
<com.google.android.material.textfield.TextInputLayout
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:hintEnabled="false"
app:helperText="helperText"
... >
<com.google.android.material.textfield.TextInputEditText
android:hint="hint"
... />
</com.google.android.material.textfield.TextInputLayout>

Android Material Ripples

I would like to follow material design guidelines in my application. For tappable text should I use unbounded or bounded surface ink ripples (displayed when the user presses on the text)?
I used this Custom ripple layout for myself, I think it is easy to use:
RippleLayout
and you can use it like this in your xml file:
<your.package.name.RippleLayout
android:layout_width="40dp"
android:layout_height="40dp"
app:mrl_rippleSelectedColorState="#android:color/transparent">
<!-- other views like buttons and.... -->
</your.package.name.RippleLayout>

In the Android full screen activity template, why does the empty style change the look of the button?

The button has is set in the activity's XML layout with:
<Button
android:id="#+id/dummy_button"
style="?buttonBarButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/dummy_button" />
The part to pay attention to is style="?buttonBarButtonStyle". The definition for the queried style is defined in styles.xml as:
<style name="ButtonBarButton" />
The style doesn't actually set any values for the button and so I can't understand why I would change anything about the button and the way it displays.
When the button is set to use the empty style, it looks like this:
But when the line style="?buttonBarButtonStyle" is removed, it looks like a standard button like this:
At first I thought that assigning the empty style would replace the default style settings for a button, but trying this in my own app doesn't change the appearance of a button at all (as I would have expected an empty style to do).
Can anybody work out exactly why this empty style is changing the look? To replicate this yourself you can create a new app using the "Fullscreen Activity".
Your ButtonBarButton and buttonBarButtonStyle has no relation to each other. You apply buttonBarButtonStyle style which is a theme attribute and defines some style for a bar button. If you can to apply your custom empty style to a button use:
style="#style/ButtonBarButton"
I'm not sure what it is that is surprising to you. The usual look of buttons is the one in the second image, so when the style is applied, that inside rectangle is removed which is a custom look. If you have seen buttons without any custom styling you would have seen that they look like the one in the second image.

Android SDK: Button becomes colored when changing the background color on LinearLayout

I have a LinearLayout in an Android app I am creating now which contains a default button with gradient gray color. This LinearLayout is now white but when I try to change the background color to yellow the button also becomes yellow which I don't want to happen. I also tried to use a color image to set the background color on the LinearLayout but the same thing happens. How do I solve this problem? Here is the code:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:background="#color/yellow">
<Button
android:id="#+id/buttonCart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
SOLVED: Wait, it actually works now. while the buttons become colored and transparent in the layout view in Eclipse the buttons is unaffected when I run the app on the phone. I thought that it would display the same result when the app is runned. Strange how it become that way in the layout view...
In that case you may set a gray background color android:background="#A4A4A4" for button also..
Just set the background on your button separately. You can use a state list drawable, i.e. a different background for each state of the button (pressed, focused, etc) to make it compeletely custom.
Why the background color changes with the layout I'm not sure. It sounds like your button is default to transparant. Check your style and theme to make sure that's not affecting what's displayed.

Categories

Resources