Is there a way to wrap text in an EditText? - android

I am setting the texts inside of EditTexts in Java. Right now, what happens is, when the text is long, it just gets cut off.
In the XML, the height of the EditText is set to wrap_content. I want the height to change depending on the length of the String I will place in it so that all the text can be seen. Any solution for this? Thanks in advance!
Edit: My EditText's setup
<item name="android:layout_width">310dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">15dp</item>
<item name="android:gravity">center</item>
<item name="android:editable">false</item>
<item name="android:textColor">#color/color_darktext</item>
<item name="android:textColorHint">#color/color_hint</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">18sp</item>
<item name="android:layout_marginBottom">8dp</item>
<item name="android:background">#drawable/button50radius</item>
<item name="android:stateListAnimator">#null</item>
<item name="android:inputType">none</item>

The reason could be your padding and restricting the width of the EditText.Please do change those values and you can notice the difference.Try changing the width to wrap_content and add the attribute maxWidth="310dp" to restrict your width.

The height of the EditText is set to wrap_content
That means it will be wrapped properly how ever long your text is, It doesn't matter.
Any solution for this ?
Yes there are some possibilities, You have not posted your XML so that it would be hard to recognize the mistake. But one of the possibility is
Your parent layout which is containing the TextView may be having the paddingBottom attribute so that your TextView won't be able to show the full text inside.
If the above one is not what you did in your case, Then you can addandroid:layout_gravity attribute,
It is Standard gravity constant that a child supplies to its parent. Defines how the child view should be positioned, on both the X and Y axes, within its enclosing layout.
You can set it to android:layout_gravity="fill" which will grow the horizontal and vertical size of the object if needed so it completely fills its container.

also set the parent layout, Layout_width property .
For example
layout_width=250sp
otherwise , EditText or TextView dont wrap to next line till it reach the end of mobile border. So define the Layout_width

Related

Customize fastScrollOverlay?

I'm trying to customize the letter popup that appears during scroll. I was able to change it's colors and the position from my styles, but I need to make the text and the whole element bigger as well as move it closer to the vertical center of the screen. Is any of these things possible? How can I do them?
This is my current code from my style.xml file:
<item name="android:fastScrollOverlayPosition">floating</item>
<item name="android:fastScrollTextColor">#000000</item>
<item name="android:fastScrollPreviewBackgroundLeft">#drawable/square</item>
<item name="android:fastScrollPreviewBackgroundRight">#drawable/square</item>
I don't have any info about further customization of the default overlay.
There's a more flexible alternative, though. You could add a TextView to your layout which only appears when the user is scrolling, and show the letter returned from your SectionIndexer's getPositionForSection method. You could then style this view exactly to your liking, and center it in a full-screen RelativeLayout.

LinearLayout with style and without orientation issue?

I have style for LinearLayout:
<style name="clickable_zone">
<item name="android:layout_height">match_parent</item>
<item name="android:layout_width">match_parent</item>
<item name="android:id">#+id/click_zone</item>
<item name="android:background">#drawable/simple_button_holo</item>
<item name="android:orientation">horizontal</item>
</style>
I use this style at different layouts as:
<LinearLayout
style="#style/clickable_zone" />
But in this case I get warning about orientation issue. Of course, I can disable this warning. But, can I resolve my problem, without disabling the warning?
UPD1. Issue message:
Checks that LinearLayouts with multiple children set the orientation
The default orientation of a LinearLayout is horizontal. It's pretty easy to believe that the layout is vertical, add multiple children to it, and wonder why only the first child is visible (when the subsequent children are off screen to the right). This lint rule helps pinpoint this issue by warning whenever a LinearLayout is used with an implicit orientation and multiple children.
It also checks for empty LinearLayouts without an orientation attribute that also defines an id attribute. This catches the scenarios where children will be added to the LinearLayout dynamically.

Customizing Android ScrollView's Vertical Scrollbar

I need to customize ScrollView so it will look like in the picture:
I already successfully customized the Thumb and the Track, but I don't know how to add Arrows like in the picture I provided.
Here is the style I'm using:
<!-- Scrollbar -->
<style name="scroll_view">
<item name="android:scrollbarAlwaysDrawVerticalTrack">true</item>
<item name="android:scrollbars">vertical</item>
<item name="android:fadeScrollbars">false</item>
<item name="android:scrollbarThumbVertical">#drawable/sb_thumb</item>
<item name="android:scrollbarTrackVertical">#drawable/sb_track_vertical_bg</item>
</style>
The Arrows should be a part of the ScrollView style to avoid extra spacing and also they need to be simple, non clickable and e.t.c.
If you want to add buttons for up and down, you can place two buttons above and below of Scrollview.And programatically scroll the scroll bar on button click.
For that purpose, you can use following code,
scrollview.scrollTo(5, 10);

Android TextView hidden when setting to single line scroll horizontal and center horizontal

I am trying to make a TextView to a fixed size, center the containing text, show the text in a single line and if the text is larger than the TextView, let the user scroll the TextView horizontal.
I almost managed to achieve this by setting this style for my TextView:
<style name="custom_text">
<item name="android:layout_gravity">center_vertical</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
</style>
The scroll works exactly how I want, the only bad thing is that the TextView is invisible when the screen shows up. To make the TextView visible it seems that I have to scroll the TextView in any direction. I tried to scroll the TextView from code in hope that the TextView will show up but no success.
How I can solve this?
Thank you!

Button scales to background image instead of content

What I need to do is have the background image just fill up the natural size of the button, as when no background is specified and the default grey background image is shown. But instead, my button scales up to the size of the background image rather than the text.
There was a previous question, but nobody had a solution.
The button:
<Button
android:id="#+id/morebtn"
style="#style/CustomButton"
android:text="More" />
I have this custom button style (greybutton is a 9-patch):
<resources>
<style name="CustomButton" parent="#android:style/TextAppearance">
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_marginLeft">10dip</item>
<item name="android:layout_marginRight">10dip</item>
<item name="android:layout_marginBottom">10dip</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_centerInParent">true</item>
<item name="android:background">#drawable/greybutton</item>
<item name="android:textSize">20sp</item>
</style>
</resources>
Right now it fills up the screen widthwise, despite being told to wrap_content. When I remove android:background from the Button style, the button shrinks down to wrap the text as expected.
Does anyone see why my background image isn't behaving like the default Button background?
Why don't you use ImageButton instead:
<ImageButton android:src="#drawable/greybutton"
android:scaleType="fitCenter" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
then you can adjust the scaling with the scaleType attribute.
The only downside is you can't set any text.
Damnit. I had an hdpi drawable that hadn't been converted to 9patch, and for some reason that was getting applied instead of the one in the mdpi drawables folder even on my mdpi screen. The background scaling actually does work as expected after all. Sorry!
(So if you're browsing this question with a similar problem, check your drawables folder to make sure you're drawing what you think you are. Also: may wish to be sure the content boundaries in your nine-patch are of the appropriate size. Note that they aren't the same as the stretchable boundaries.)
You could try hard coding the height and width of the buttons using dip. That will be an issue if you need the Text on the buttons to change but it should work to restrain the button from expanding to the size of the image. Of course a large image will make the button larger.. the width / height is wrap_content, and the image is clearly part of the content... try hardcoding width / height parameters.
Add these two items to your CustomButton style
<item name="android:minWidth">0dp</item>
<item name="android:minHeight">0dp</item>

Categories

Resources