My Codename One app has to feature something like Android Chip controls, or equivalent.
They are used in two places and the layout is:
-for the first place
<com.google.android.material.chip.ChipGroup android:id="#+id/chip_group" android:layout_width="wrap_content" android:layout_height="wrap_content">
<com.google.android.material.chip.Chip android:text="#string/first_chip_title" android:id="#+id/first_chip" android:layout_width="match_parent" android:layout_height="wrap_content" app:closeIconEnabled="false"/>
<com.google.android.material.chip.Chip android:text="#string/second_chip_title" android:id="#+id/second_chip" android:layout_width="match_parent" android:layout_height="wrap_content" app:closeIconEnabled="false"/>
...
...
</com.google.android.material.chip.ChipGroup>
-for the second place
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="#+id/chip_list"
...
...
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="0dp" android:layout_marginRight="0dp" app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" tools:listitem="#layout/content"/>
</LinearLayout>
where the content (it's the element of the RecyclerView) is:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content">
<com.google.android.material.chip.Chip android:id="#+id/chip_element" android:layout_width="wrap_content" android:layout_height="wrap_content" app:closeIconEnabled="false" android:textAllCaps="false" android:layout_gravity="center_vertical" style="#style/Widget.MaterialComponents.Chip.Filter" android:layout_weight="1" />
</LinearLayout>
(Some layout parameters are included as they are in the code although they are not important here)
here's the effective layout (the example is for the second type of layout, the first one is just a simpler version):
What could be the equivalent in Codename One?
Flow layout breaks lines pretty seamlessly. It's the default layout for Container. I can use labels or buttons to build stuff like that pretty easily. Notice I didn't use UIIDs here which you need to use to add margin/padding so the chips are more distinct from one another:
Container chips = new Container();
// note you can use Button to make them clickable and UIID to style
// them any way you want
chips.add(new Label("a very long label for a chip"));
// I can check the chip manually
Label checked = new Label("another label");
checked.setMaterialIcon(FontImage.MATERIAL_CHECK);
checked.setTextPosition(RIGHT);
checked.getAllStyles().setBorder(RoundBorder.create()
.rectangle(true)
.color(0xaaaaaa));
chips.add(checked);
chips.add(new Label("chip label 2"));
chips.add(new Label("chip label 3"));
chips.add(new Label("chip label 4"));
chips.add(new Label("chip label 5"));
chips.add(new Label("short label"));
chips.add(new Label("very long label for chip"));
hi.add(chips);
Related
I am having a prefix text in a Text Input Layout but it only shows when i click inside the Text Input Edit Text which is inside the Text Input Layout that has my prefix text. How can i make the prefix text to always show with the hint
Below is my Text Input Edit Text
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/til_number"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/til_country"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
app:boxBackgroundColor="#EFEFF2"
app:prefixText="+01 - "
app:shapeAppearanceOverlay="#style/RoundedTextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/et_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="#string/number"
android:inputType="phone"
android:maxLength="100"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
What i would like to achieve is
+01 -
the above text in prefix should always show
i have tried doing the following below
app:prefixTextColor="#color/secondaryDarkColor"
If you check the logic of the view, you will see the prefix text will be hidden if:
prefixTextView.setVisibility((prefixText != null && !isHintExpanded())
? VISIBLE : GONE);
Add app:expandedHintEnabled="false" to your TextInputLayout and your prefix text will stay visible:
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/text_input_layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:expandedHintEnabled="false"
app:prefixText="MyPrefix: ">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/text_input_edit_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="My optional Hint" />
</com.google.android.material.textfield.TextInputLayout>
Note: Of course the hint will show on top like this.
From the Material.io website, you can use:
Adding a prefix/suffix to a text field: app:prefixText="#string/prefix"
Inside your com.google.android.material.textfield.TextInputLayout.
The Android Studio preview will not show the prefix in the text view but if you run the application on a device, when the user selects the input text, the prefix will be shown. Below there are the screenshots of what i tested.
With the input layout not selected
With the input layout selected (my_prefix if what i used as text prefix in the xml, and typed text is what i added from the keyboard)
If you want to show the suffix when the hint is not expanded using Kotlin:
textInputLayout.viewTreeObserver.addOnGlobalLayoutListener {
textInputLayout.suffixTextView.visibility = View.VISIBLE
}
Fragment background layout is shrinking when the virtual keyboard is display on an editText input; how can I fix this.
<EditText
android:id="#+id/age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="79dp"
android:layout_marginRight="79dp"
android:digits=" 0123456789"
android:gravity="center"
android:hint="..."
android:inputType="textVisiblePassword" />
I want to increase space between text and it's underline. I can change line height but I don't change height between text and it's underline.How can I do this ?
private static final String FONTH_PATH = "fonts/Brandon_bld.otf";
...
selectTextView = (TextView) findViewById(R.id.selectTextView);
selectTextView.setTypeface(font);
SpannableString content = new SpannableString(getResources().getString(R.string.select_your_prove_type));
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
selectTextView.setText(content);
...
and xml file
<TextView
android:id="#+id/selectTextView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="536"
android:gravity="left"
android:lineSpacingMultiplier="0.8"
android:text="#string/select_your_prove_type"
android:textColor="#color/Blue"
android:textSize="#dimen/select_size" />
Just use the
paddingBottom
as follows
<android.support.design.widget.TextInputLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="#+id/fragment_activity_edit_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="16dp"
android:hint="Description"
android:textSize="34sp"
tools:text="Secret Death Ray Design"/>
</android.support.design.widget.TextInputLayout>
Okay here's a more complete answer:
In your styles.xml, add a style:
<style name="MyTour.HeadingText">
<item name="android:background">#drawable/tour_header_line_layerlist</item>
</style>
Now create a tour_header_line_layerlist.xml file with content:
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="20dp" android:drawable="#drawable/tour_header_line"/>
</layer-list>
The above will set a margin top of 20dp for the line (extract it out to dimen.xml for completeness)
Now create the corresponding tour_header_line.xml:
<shape android:shape="line"
xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="1dp"
android:color="#color/tour_subheading_color" />
Now reference the style in your control:
<TextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/tour_1_heading_text"
android:id="#+id/heading_text" android:layout_gravity="center_horizontal"
style="#style/MyTour.HeadingText" //notice this
android:layout_marginTop="#dimen/margin_large"/>
Let me know if you have other questions!
Add these line in EditText
<EditText
...
android:includeFontPadding="true"
android:paddingBottom="20dp" />
You can add the custom underline with a drawable file (in my case I've created a shadow) and set this custom underline with
android:background="#drawable/shadow_file.xml"
After that with adding padding to your EditText you can add more space between the line and the text.
android:paddingBottom="#dimen/underline_space"
and define this dimension on your dimens.xml file.
That works for me, and I hope for you too :)
Please don't mark this question as duplicate. Why? because I am going to explain why it's not.
Below are the steps I have done:
Create a RelativeLayout
Created LayoutPArams for it as wrap_content and wrap_content
Created 1st TextView , gave it an id
Created LayoutParams for first textview and added it to the RelativeLAyout
Created Second TextView
Created LayoutParams for it, added a rule to be right_Of of id_for_first_tetview
Same step for Third Textview, except it's right_of the second textview
The problem here is: The first text view has text which extends to the second line, and when the text extends to the second line, the width of this i.e. the first textview occupied the whole width, and hence the other textview either overlaps or comes below it.
Let me demonstrate that with a diagram:
Want:
Happening:
So in short, is there a way to keep the textviews in one row and even if one textview takes up two rows, the second textview can start right after where the text for forst Textview ended ?
Thank you in advance. I could really use some help.
This can be done with LinearLayout with weight easily.
Method 1 - XML (give required padding or margins)
<LinearLayout
android:layout_width="match_parent"
android:weightSum="3"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextViewTextViewTextViewTextView" />
<TextView
android:id="#+id/textView4"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
Method 2 - Programmatically (give required padding or margins)
tv2 = (TextView)findViewById(R.id.textView2);
tv3 = (TextView)findViewById(R.id.textView3);
tv4 = (TextView)findViewById(R.id.textView4);
android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1f);
tv2.setLayoutParams(params);
tv3.setLayoutParams(params);
tv4.setLayoutParams(params);
In Android, I'm trying to accomplish this:
Basically, the ability to add the button side by side with an EditText, where they both take up 90% of the width of a top row. (I'm not concerned with having a logo like the twitter icon).
I've tried LinearLayout with layout_weight, but they didn't appear properly at all:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum = "1.0"
android:orientation="vertical"
android:background = "#faadadad" >
<EditText
android:layout_width="0dip"
android:layout_height="0dip"
android:layout_weight = "0.8"
android:layout_marginLeft = "2dip"
android:layout_marginTop = "1dip"
android:layout_marginBottom = "1dip"
android:hint="Search Terms" />
<Button android:text = "?"
android:layout_width = "0dip"
android:layout_height="2dip" android:layout_weight = "0.2"/>
</LinearLayout>
and anything I tried in RelativeLayout just didn't look right (I tried setting the margin between the 2 element to 0dips, no luck. Also I couldn't get the 90% of the width requirement either.)
What am I doing wrong? Thanks in advance.
Try using following:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum = "1.0"
android:orientation="horizontal"
android:background = "#faadadad" >
<LinearLayout android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft = "2dip"
android:layout_marginTop = "1dip"
android:layout_marginBottom = "1dip"
android:hint="Search Terms" />
</LinearLayout>
<Button android:text = "?"
android:layout_width = "0dip"
android:layout_height="wrap_content"
android:layout_weight = "0.2"/>
</LinearLayout>
So basically, when you using, horizontal LinearLayout, then layout_weight works horizontally i.e. width is divided according to layout_weight parameter (layout_width="0dp"). If you are using vertical LinearLayout, then layout_weight works vertically i.e. height is divided vertically according to layout_weight parameter (layout_height="0dp").
Hope it will be helpful to you.