this is my string.xml
<string name="terms_condition"> Accept the <u>Terms & Conditions</u></string>
this is mytextview
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/terms_condition"
android:padding="25dp"
/>
</android.support.constraint.ConstraintLayout>
i am using this code for display underline text but there is no space between two string. how keep space between two text and how to reduce underline? in below screen you can see underline problem.
<string name="terms_condition"> Accept the\n<u>Terms & Conditions</u></string>. I think this should work.
Related
I want to use autosizing TextView for dynamic text content.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="350dp"
android:autoSizeTextType="uniform"
android:hint="hint"
android:text="some dynamic text" />
</LinearLayout>
This works so far:
But there is an issue if the dynamic text content is empty. The TextView wraps each character of the hint content to a new line:
I expect hint to behave like text. How to resolve this without hacks like setting text content to hint content if the former is empty.
The same event happened to me.
I defined this and it fixed it.
app:autoSizeStepGranularity="1dp"
I'd definitely set the minimum and maximum sizes together.
android:hint="no message"
app:autoSizeMaxTextSize="20sp"
app:autoSizeMinTextSize="1sp"
app:autoSizeStepGranularity="1sp"
app:autoSizeTextType="uniform"
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/show"
android:layout_width="match_parent"
android:layout_height="350dp"
android:hint="no message"
/>
</RelativeLayout>
MainActivity.java
TextView shows = findViewById(R.id.show);
TextViewCompat.setAutoSizeTextTypeWithDefaults(shows,
TextViewCompat.AUTO_SIZE_TEXT_TYPE_UNIFORM);
if(message.isEmpty()){
shows.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
}else{
shows.setText(message);
shows.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
}
if you add this code please run the code.
I have a random message that contains escape characters. I found that TextView displays wrong spaces for escape characters "\t".
My sample project has an Activity that has a layout with only one TextView.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="#+id/tv_hello"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="#string/text_hello"
android:maxLines="5"
/>
</FrameLayout>
I define text in file strings.xml
<string name="text_hello">Click Change: 13894\t18258\nClick Change: 1604\t2190\nClick Change: 9250\t11962</string>
The corresponding result is
I change the text like below
<string name="text_hello">ABC: 13894\t18258\nDEF: 1604\t2190\nXYZ: 9250\t11962</string>
The corresponding result will changes
As sample, TextView displays wrongly space. Can anyone has a solution to fix this issue?
You can use
\u0020
or
instead of \t in string.xml file.
I am new to Android. I am reading official documentation of Android about linear layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="15dp"
android:paddingRight="15dp"
tools:context="com.example.hassan_microsoft.a2ndday18122017.MainActivity">
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:hint="#string/to"/>
At this line => android:hint="#string/to"
it is giving error and not working as i want it to be worked.Picture1
this preview (Picture1) should be the result but mine is giving out as this one as below (Picture2). Picture2 What can be the problem.? Thanks.
Try this make your EditText hight to android:layout_height="wrap_content"
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:hint="#string/to"
/>
And also
You need Create a new string resource value in value res/values/String.xml like below code
<string name="to">To</string>
You need to declare the value of #string/to in your strings.xml
Go to app -> res -> values -> strings.xml
Create a new string value called to with the string value, it should look like this::
Sample App
<string name="to">To</string>
A simpler alternative would be to just change your hint value to :
android:hint="To"
I am switching between text and design view in android studio and it seems that whenever I make a change in the text (xml) and the change back to design my changes are overwritten by something random. I want the text changes to take priority over the design tab.
For example:
I have this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.foo.MainActivity">
<RelativeLayout
android:layout_width="368dp"
android:layout_height="wrap_content"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp">
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
change it into this in text view:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.test.foo.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
when I switch to Design it somehow resets back to the first one. I want to see my changes even if they are wrong, without starting an emulator. I tried googling it but I can't see anybody else reporting this.
I am using the PlaceAutocompleteFragment that is provided by google in a project that I am working on right now. But the problem is I need to display the place name that I've selected from the autocomplete widget but the whole text in not showing because the default textsize in the widget is too big. So, is there any way I can change the textsize in the PlaceAutocompleteFragment without creating my own custom search UI?
My XML code:
<android.support.v4.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.baldysns.capedbaldy.materialdesigntest.activity.DrawerMainActivity"
tools:openDrawer="start">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar_drawer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:id="#+id/lnr_google_searchbar"
android:layout_width="match_parent"
android:layout_height="35dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/btn_white_notboerder">
<fragment
android:id="#+id/place_autocompletehome_fragment"
android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</LinearLayout>
<FrameLayout
android:id="#+id/container_body"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.ibaax.com.ibaax.FragmentDrawer"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_drawer"
tools:layout="#layout/fragment_drawer" /></android.support.v4.widget.DrawerLayout>
And a screenshot of the problem:
Using fragment instance you can change the font size and whatever you want with the Search box EditText.. this is how you need to do
// placeAutocompleteFragment - is my PlaceAutocompleteFragment instance
((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
UPDATED: 05/26/20
Looks like in latest SDK view id is changed to R.id.places_autocomplete_search_input
The autoCompleSupportFragment has an EditText Property. Which can be modified accordingly.
The name of the editText is however not very clear. In my case, it was "a"
autoCompleteFragment.a.gravity = Gravity.START
so to modify the text size, i did:
autoCompleteFragment.a.textSize = 14.0f
View fView = autocompleteFragment.getView();
Set Text, Hint Color & Size:
EditText etTextInput = fView.findViewById(R.id.places_autocomplete_search_input);
etTextInput.setTextColor(Color.WHITE);
etTextInput.setHintTextColor(Color.WHITE);
etTextInput.setTextSize(12.5f);
Set Search Custom Image:
ImageView ivSearch = fView.findViewById(R.id.places_autocomplete_search_button);
ivSearch.setImageResource(R.drawable.ic_search_white);
Set Search Text Clear Image:
ImageView ivClear = fView.findViewById(R.id.places_autocomplete_clear_button);
ivClear.setImageResource(R.drawable.ic_close_white);
Output:
Simplest
((EditText)findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
in case of skadosh answer you need to first get instance of fragment.
Assuming your fragment in the Javacode is autocompleteFragment, you can use
autocompleteFragment.a.setTextSize(12.0f);
Your screen shot shows that you set margin or padding at search icon and cancel icon. remove it so it make more space for text view.
You can also use autofittextview library(https://github.com/grantland/android-autofittextview) which will make text size according to your text view size.