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"
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.
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.
I pulled this section of code from: https://github.com/slodge/MvvmCross-Tutorials/blob/master/MoreControls/MoreControls.Droid/Resources/Layout/FirstView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Mvx.MvxSpinner
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
local:MvxBind="ItemsSource Shapes; SelectedItem Current" />
<!--
could be customised using
local:MvxDropDownItemTemplate="#layout/spinner_dropdownitem_shape"
local:MvxItemTemplate="#layout/spinner_item_shape"
-->
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text Current" />
<MC.ShapeView
android:layout_width="fill_parent"
android:layout_height="300dp"
local:MvxBind="Shape Current" />
</LinearLayout>
The comment mentions it is possible to customize the look by passing MvxDropDownItemTemplate and MvxItemTemplate a layout. Let's assume we are going to use this simple layout for both templates:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Project.Ui.Droid"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Text ???????" />
</FrameLayout>
The MvxSpinner displays the enumerated name (Circle, Square, Triangle) as the text for each item. Without changing the view model, is it possible to create a binding, in the template, that displays the same thing the MvxSpinner displays by default when no template is used? If so, what would that binding look like? If that's not possible, what is the best way to accomplish this outcome?
in the template, that displays the same thing the MvxSpinner displays by default when no template is used? If so, what would that binding look like? If that's not possible, what is the best way to accomplish this outcome?
The default template uses ToString() on the object.
To achieve the same thing, you can use the Whole Object binding. From the wiki, you should be able to specify using an empty Path or a single Period for the Path. Since we've seen some issues reported recently with empty Path binding, I recommend using a Period:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/Project.Ui.Droid"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:MvxBind="Text ." />
</FrameLayout>
i would like to know why eclipse is showing warning "[I18N] Hardcoded string "TextView", should use #string resource" in the xml code below .Actually i am trying to get the text written by user in an edit Text in an activity to this current activity.
<?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:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.01"
android:text="TextView" />
</LinearLayout>
The reason that you are receiving a warning, is due to the fact that you are trying to hardcode a string which is not good convention in Android programming due to possible redundancy:
<TextView
...
android:text="TextView" />
You should rather create a reference to a string in the .../res/values/strings.xml file like so:
<TextView
...
android:text="#string/TextView" />
.. and define it in your strings.xml file:
<string name="TextView">TextView</string>
Hope this helps.
As it says, you are using a "hard-coded" string which is less efficient than using the String resource. Simply remove
android:text="TextView"
if you don't want the warning to show. If you want it there then disregard the warning or add it to the String resource file. The Text property isn't needed. If you are expecting user input then you should change it to an EditText anyway unless you have a reason for using TextView
<EditText
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.01" />
Then if you want it to display something such as "Enter input here" in the View then you can add android:hint"Text to display". But this will give you the same warning if you don't add it to the strings.xml and use android:hint="#string/nameInStringsFile".
But these warnings are just that. Suggesting possibly more efficient methods or ways of implementing whatever you are doing.
Change the XML to the following to remove the warning
<?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:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="0.01" />
</LinearLayout>
The reason you are seeing the warning is because you had set the text to "TextView" inside the XML layout file. It is Android best practice to put all Strings inside the strings.xml file in your res/values folder which creates string resources. One you have a string in a resource file you can reference it from your layout file using the syntax "#string/string_name".
caution [I18N] Hardcoded string"Would you like to give Zohan a call?", should use #string resource
<?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:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Would you like to give Zohan a call?"
android:layout_marginTop="200dp"
android:layout_marginLeft="20dp"
android:textSize="18dp"/>
You should not hard code your strings. Instead you should put your strings in values/strings.xml.
Ctrl+1 on the error it will show you the way to fix it.
Refer to the android string documentation: http://developer.android.com/guide/topics/resources/string-resource.html#String
You should store your texts in a resource properties file and link them to your XML file using the # notation.
See this link for more information.