How to display placeholder Chips within ChipGroup in xml? - android

I have a layout with a ChipGroup whose chips will be populated programmatically, but I want to visualise how chips will look like within the layout, is there a way to show fake chips like for example using the tools namespace?

Not really the solution, you asked for, but it gets the job done.
If someone's got a better solution, let me know.
I solved it with a hardcoded chip, which has the visibility set to GONE and inside the tools namespace visibility set to VISIBLE.
<com.google.android.material.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
tools:visibility="visible"
tools:text="Leichter Genuss" />

Related

Android Accessibility with ConstraintLayout

I want to add Accessibility features to my Android app. To provide the best UX for users, I need to add focusable="true" and contentDescription tags to all control elements on the screen. The problem is, I have used ConstraintLayout. For example, I have button that consists of two ImageViews:
<ImageView
android:id="#+id/outside"
app:layout_constraintTop_toBottomOf="..."
app:layout_constraintBottom_toTopOf="..."
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
style="#style/outsideElement"
/>
<ImageView
android:id="#+id/inside"
app:layout_constraintBottom_toBottomOf="#+id/outside"
app:layout_constraintEnd_toEndOf="#+id/outside"
app:layout_constraintStart_toStartOf="#+id/outside"
app:layout_constraintTop_toTopOf="#+id/outside"
style="#style/insideElement"
/>
Now, when TalkBack or Accessibility Scanner applied, first it shows outside element and then inside element. I would like to have focusable both of them. The problem is in flat structure. If I would have both of them in RelativeLayout, LinearLayout, etc., I just need to add focusable="true" to the upper layout. But I want to keep flat structure and ConstraintLayout. Any idea how to solve it with flat structure? Thanks in advance.

Separator view with/without headers as per Android Material Design Guideline

I am trying to create a separator with header per Google Material Design spec, and I couldn't get it to work. Why would google roll out a spec that is not even available on either support or target platform level? So here I am recreating material spec to work with the older version and here is what I got so far:
<TextView
android:id="#+id/textview_task_header1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:layout_marginBottom="12dp"
android:drawableTop="#drawable/drawable_separator"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#bfbfbf"
android:text="Location"/>
I want to create a header, a separator of some sort. I don't want to use list because list will require me to create an adapter which I find really impractical in my case. I have to layout the UI using XML and I can't figure it out.
I need something to look like this, I need to have a header without the line separator and a header with one separator:
Also, I was able to achieve to create a header via TextView and set margin top and bottom. The problem is I can't show the drawable line on my case and I don't feel like I am doing the right thing here. Its too messy.
I appreciate if you don't post an answer indicating the use of a hackish solution. I don't like to go down that path for some reason. :/
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
To add vertical separator, switch the layout_width and layout_height values

Trying to put several textviews in a Button

I think I might be doing something stupid but I cannot find the answer. Obviously ht ebelow thing doesn't work but how would I do it?
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+#id/date"
android:text="+#id/heading"
android:text="+#id/subheading"
android:drawableLeft="+#id/featuredimage"
/>
I'm basically making an articlebutton to represent an article for a blog. I tried putting textviews inside but it miscounted the ending tags and threw an error.
What is that best way to create one of these buttons?
Dont use Button.
Use a Linear/Relative layout, with the attribute:
android:clickable="true"
Inside this layout add all your TextViews or any other thing you want.

Creating such a Button with Android? (Inspired by iOS)

On an iOS App I saw such a Button:
The same I would like to do in Android, how could I achieve this?
What I tried is the following code:
<Button
android:id="#+id/widget41"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="Email1 testmail#gmail.com"
android:textStyle="bold" />
Looks something like that:
Well just a normal (ugly looking) Button. I have no idea, how I could style it like in iOS. Any suggestions or links would be appreciated!
The best solution would be to create your own custom view that behaves like the iOS counterpart (though, as other users have mentioned, Android does have it's own design guidelines, and the view that you are seeing is an iOS implementation that is designed for that platform).
If you look at the iOS image above (a copy of yours with some parts highlighted), I have split it up into sections.
You could use an Android ViewGroup like a LinearLayout to create the overall image, and give the LinearLayout a border or background (which can be a bitmap image of a rounded rectangle for example (See Android Nine Patch for an example of how to make this fit multiple screens).
Firstly, for the mail icon you would need a LeftAligned ImageView
with appropriate dimensions.
Next up we have a Bold TextView containing the text "Email1".
This is followed by another TextView which is blue and uses the
elipsize property (as defined in an Android XML layout) to create
"..." at the end once the text has reached the max width it can
consume. (Use android:ellipsize="end" in the XML)
Finally we have an indicator image, which again can be an ImageView
sized appropriately.
You could also achieve this with a RelativeLayout, which would allow you to RightAlign the indicator image, LeftAlign the mail icon, and allow the text to fill the space in between that it can get hold of.
Example of Nine Patch use for the background here
That is UITableView in iOS(just like ListView in android). It depends on the list item design you do it. There is no such Button Control in Android.
You should design your own button to looks like iOS one.
Android has it own design guidelines:
http://developer.android.com/design/patterns/pure-android.html
Well, as others have clearly mentioned there is no default Button in Android like this, and for your info neither is in iOS. Its all about the design. Anything is possible, in the end it all comes to how far are you willing to go to achieve it.
Below is a simple code, that will be close to your design.
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_margin="5dp"
android:background="#drawable/text_background"
android:drawableLeft="#drawable/envelope"
android:drawablePadding="10dp"
android:drawableRight="#drawable/right_arrow"
android:ellipsize="end"
android:gravity="center_vertical"
android:text="#string/email" />
There can be other ways also, like that whole view could be a ViewGroup, either a LinearLayout or a RelativeLayout and there could be multiple TextViews and ImageViews inside that.
Here is a tutorial for creating stylized android buttons. You can round the corners and change the background colors to look like the buttons in ios.
Here is a similar question.
Hope this helps.

How to make a sectionised ListView

I have been searching all day on how to make these sections in a ListView. Haven't found anything yet. I have been through many blogs and most of them talk about the approach CommonsWare takes (i.e. SectionAdapter) but the SectionAdapter.java is nowhere to be seen on his GitHub repo.
How can this be made? (i.e. the part marked A. I am not trying to make a Preferences list. Something more on the lines of a Contact List)
I struggled a lot on this. There are a number of ways to do this. The one I found simplest and which I recommend is using separator view in your list item layout (the one you inflate in get view) and change its visibility based on whether on not there should be a header. I use something like this:
<TextView
android:id="#+id/separator"
android:layout_width="fill_parent"
android:visibility="gone"
android:layout_height="wrap_content" />
I found this much simpler than the other adapter. I just kept track of where I wanted to have a separator using a variable and based on that I setVisibility(View.VISIBLE) in my getView().
Try putting this on the textview in the xml:
<TextView
style="?android:attr/listSeparatorTextViewStyle"
android:id="#+id/tv_separator"
android:visibility="gone"
/>
this will make it like preferences categories that looks much better..

Categories

Resources