I am sorry to ask this silly question but I am unable to set textcolor property in android xml.
This is my code:
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textStyle="bold"
android:textColor="#color/TextColor"
android:textSize="35dp"
android:layout_gravity="center_horizontal"/>
and color :
<color name="TextColor">#00427E</color>
I am able to see this color change in preview screens but not in real device.
My .gradle includes:
compile 'com.android.support:appcompat-v7:23.1.1'
Please help
You can use Programmatic Way
setTextColor(Color.parseColor("#00427E"));
Or
setTextColor(getResources().getColor(R.color.TextColor);
Try Textview xml code
<TextView
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textStyle="bold"
android:textColor="#00427E"
android:textSize="35sp"
android:layout_gravity="center"/>
IF don't Work this code use This Java side
setTextColor(Color.parseColor("#00427E"));
Sometime it happen may be if your Android Studio have lot of cache. so try to clean cache.
go to File > invalidate Caches / Restart click on it. may be solve your problem.
I face same problem. I think it is device specific problem. I tested in nexus,and motorola devices its working fine but pick a device default color in MI devices. To resolve this issue set the text color programaticly.
TextView textView = (TextView) findViewById(R.id.yourid);
textView.setTextColor(ContextCompat.getColor(this,R.color.TextColor));
from what you have written, the implementation should work:
android:textColor="#color/TextColor"
is the attribute which changes the color of the text.
What i would suggest is, check the background color of the layout in which this TextView is placed. It is possible that the background color is the same as the color you are trying to set on the TextView, that is why you are not able to see the difference.
If you want to be double sure, set a black or white color on the TextView and see if it appears on as desired on screen.
If you still do not get the desired result, paste the full xml here so that we have a better idea of what's going on.
Suddenly occurs problem with custom fonts.
When i apply comic font for text views,first letter is cut. I try to implement paddings and margins but unfortunately still first letter is cut.
Images that are presented describe this problem.
I consider this flow as well but no results.
This is xml textview implementation.
<com.alllarm.alllarm.AutoResizeTextView
android:id="#+id/settings_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="#string/my_profile"
android:textColor="#android:color/white"
android:textSize="35sp" />
This issue is connected with wrong size of the textview.To solve this problem you need just adjust additional size to the textview item. Additionally this could be connected with wrong text font feature.
I am Working on Project with inside i want to Use custome image for Checkbox checked/unchecked event.
inside my login xml i have write :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp" >
<CheckBox
android:id="#+id/chk_remember_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_uncheked"
android:paddingLeft="5dp"
android:text="Remember Me"
android:textColor="#024d94"
android:textSize="12dp" />
</LinearLayout>
Here i have Used android:paddingLeft="5dp" for getting space between button and textview.
My Problem : i got two different views for 2.3 and 4.2
for Device that has xhdpi or below density or that has large screen i
am getting below screen (this one is perfect as i want ):
for Device that has hdpi or below density or that has normal/small
screen i am getting below screen :
Can anyone tellme where am i missing? or anything Wrong in my layout?
I want the same layout screen which i am getting for 4.2 device in normal/large screen devices.
Thanks in advance.
It appears that Checkbox already uses padding by default internally and overriding it with paddingLeft causes these issues. You should remove that property from your XML.
If you still want to adjust the padding, you will have to do so programatically. See this answer: https://stackoverflow.com/a/4038195/832776
To only apply it to >4.2 you can use the following, though I would test on emulators to make sure this issue isn't merely a problem with just your devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Give the fixed width to check box hopefully this can resolved your problem.
Don't give padding, it comes by default with Checkbox.
This is my XML for my check box:
<CheckBox
android:id="#+id/atm_checkbox"
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#color/input_color" />
And it looks like this:
http://imageshack.us/photo/my-images/528/47342915.png/
This is what i found on internet:
<CheckBox
android:id="#+id/chkAndroid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/chk_android"
android:checked="true" />
which looks like this
how to change my checkbox to look like the one i found on internet.
As my rep is <10 i cant upload image of my checkbox, or can anyone help me how to style checkbox to make it look better
I think both the xmls have similar code, but why are they looking so different?
If you want custom the look of checkbox see this tutorial and find everything.
By the way, the checkbox from your link is for Android3.0 and above.
CheckBox derive from Button class, so you can set a background image like button. See this link, may be it is what you are looking for.
If you want a clean design without codes, use:
<CheckBox
android:id="#+id/checkBox1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableLeft="#android:color/transparent"
android:drawablePadding="10dp"
android:text="CheckBox"/>
The trick is to set colour to transparent for android:drawableLeft and assign a value for android:drawablePadding. Also, transparency allows you to use this technique on any background colour without the side effect - like colour mismatch.
Does any one know how to wrap text in TextView in Android platform. i.e if the text in textview exceed the screen length it should be displayed in the second line.
I have searched and tried the following:
android:scrollHorizontally="false",
android:inputType="textMultiLine",
android:singleLine="false"
But none work..
Can anyone suggest how can I do it.
Constraint Layout
<TextView
android:id="#+id/some_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="#id/textview_above"
app:layout_constraintRight_toLeftOf="#id/button_to_right"/>
Ensure your layout width is zero
left / right constraints are defined
layout height of wrap_content allows expansion up/down.
Set android:maxLines="2" to prevent vertical expansion (2 is just an e.g.)
Ellipses are prob. a good idea with max lines android:ellipsize="end"
0dp width allows left/right constraints to determine how wide your widget is.
Setting left/right constraints sets the actual width of your widget, within which your text will wrap.
Constraint Layout docs
For me this issue only occurred on Android < 4.0
The combination of parameters I used were:
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
The maxLines count seemed to be the random final piece that made my TextView wrap.
For the case where the TextView is inside a TableLayout, the solution is to set android:shrinkColumns="1" on the TableLayout. (Replace 1 with the column number the TextView you want to wrap is in. (0-indexed))
AFAICT, no other attributes are needed on the TextView.
For other cases, see the other answers here.
FWIW, I had initially gotten it to sort of work with
<TextView
android:id="#+id/inventory_text"
android:layout_width="fill_parent"
android:layout_weight="1"
android:width="0dp"
but that resulted in some extra empty space at the bottom of the Dialog it was all in.
Use app:breakStrategy="simple" in AppCompatTextView, it will control over paragraph layout.
It has three constant values
balanced
high_quality
simple
Designing in your TextView xml
<android.support.v7.widget.AppCompatTextView
android:id="#+id/textquestion"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:scrollHorizontally="false"
android:text="Your Question Display Hear....Your Question Display Hear....Your Question Display Hear....Your Question Display Hear...."
android:textColor="#android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:breakStrategy="simple" />
If your current minimum api level is 23 or more then in Coding
yourtextview.setBreakStrategy(Layout.BREAK_STRATEGY_SIMPLE);
For more refrence refer this BreakStrategy
You must use 2 parameters :
android:ellipsize="none" : the text is not cut on textview width
android:scrollHorizontally="false" the text wraps on as many lines as necessary
This should fix your problem: android:layout_weight="1".
By setting android:maxEms to a given value together with android:layout_weight="1" will cause the TextView to wrap once it reaches the given length of the ems.
OK guys the truth is somewhere in the middle cause you have to see the issue from the parent's view and child's. The solution below works ONLY when spinner mode = dialog regardless of Android version (no problem there.. tested it in VD and DesireS with Android =>2.2) :
.Set you spinner's(the parent) mode like :
android:spinnerMode="dialog"
Set the textview's(child custom view) properties to :
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
I hope this works for you also.
In Android Studio 2.2.3 under the inputType property there is a property called textMultiLine. Selecting this option sorted out a similar problem for me. I hope that helps.
Just was working on a TextView inside a layout inside a RecyclerView. I had text getting cut off, ex, for Read this message, I saw: Read this. I tried setting android:maxLines="2" on the TextView, but nothing changed. However, android:lines="2" resulted in Read this on first line and message on the 2nd.
Try #Guykun's approach
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
Also, make sure that parents width is not set to wrap content. This is the thing that I was missing.
I had the same problem. Following change made it work -
android:layout_width="wrap_content"
The ellipsis, maxLines, or layout_weight - all didn't make any difference.
Note - The parent width is also set as wrap_content.
All you have to do is to set your textview width.
android:layout_width="60dp"
you can change the width to your choice. Just type long sentence to check if it working like this
android:text="i want to be among world class software engineer"
I am using Android 2.2 and my textview will automatically goto the next line if it exceeds the screen.
If you would like to have the text goto the next line before the end of the screen, just add in (just put in your own dp value). This will be useful if you have a picture on the right of the text.
android:layout_marginRight="52dp"
Strange enough - I created my TextView in Code and it wrapped - despite me not setting anything except standard stuff - but see for yourself:
LinearLayout.LayoutParams childParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
childParams.setMargins(5, 5, 5, 5);
Label label = new Label(this);
label.setText("This is a testing label This is a testing label This is a testing label This is a testing labelThis is a testing label This is a testing label");
label.setLayoutParams(childParams);
As you can see from the params definition I am using a LinearLayout. The class Label simply extends TextView - not doing anything there except setting the font size and the font color.
When running it in the emulator (API Level 9) it automatically wraps the text across 3 lines.
Just set layout_with to a definate size, when the text fills the maximum width it will overflow to the next line causing a wrap effect.
<TextView
android:id="#+id/segmentText"
android:layout_marginTop="10dp"
android:layout_below="#+id/segmentHeader"
android:text="You have the option to record in one go or segments(if you swap options
you will loose your current recordings)"
android:layout_width="300dp"
android:layout_height="wrap_content"/>
The trick is with the textView width, try to make it dedicated number like:
<TextView
android:layout_width="300dp"
android:layout_height="wrap_content"/>
I've tried many solutions without any result, I've tried:
android:ellipsize="none"
android:scrollHorizontally="false"
the only one thing triggred the wrap option is the dedicated width
You need to add your TextView in a ScrollView with something like this :
<ScrollView android:id="#+id/SCROLL_VIEW"
android:layout_height="150px"
android:layout_width="fill_parent">
<TextView
android:id="#+id/TEXT_VIEW"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header This text view should act as header" />
</ScrollView>