I have created an EditText using:
<style name="foredits">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:singleLine">true</item>
<item name="android:maxLines">1</item>
<item name="android:scrollHorizontally">true</item>
<item name="android:typeface">monospace</item>
<item name="android:imeOptions">actionNext</item>
</style>
When creating the EditText,I put in a layout_weight,an id and a id as other attributes.I would like the EditText to scroll horizontally when:
a.hint does not fit within the bounds of the edittext
b.text is being entered and the text goes past the right edge of the edittext's bounds
Because,this has not been scrolling horizontally,I have also tried with a ScrollingMovementMethod
edit_mul.setHorizontalScrollBarEnabled(true);
edit_mul.setMovementMethod(new ScrollingMovementMethod());
This does not seem to work either.How do I get this working?
Your code seems good i did the following for vertical Scroll Bar
xml
<TextView
android:id="#+id/response_sms_textView3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="#color/White"
android:gravity="center"
android:lines="8"
android:maxLines="8"
android:scrollbars="vertical" <!-- include -->
android:text="#string/without_account_response_sms_tv3"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/Black" />
code
tv3.setMovementMethod(new ScrollingMovementMethod()); // include
but if you put this inside ScrollView layout might not work. Thanks
You can use the following parameters in the edittext.
edittext.setFocusable(false);
edittext.setClickable(false);
edittext.setFocusableInTouchMode(false);
edittext.setEnabled(true);
edittext.setKeyListener(null);
edittext.setHorizontallyScrolling(true);
So it will work as the desired behaviour.
Related
I am trying to put two text view within the circular progress bar as shown in the picture below. These two text should be aligned with center of the circular progress bar.
But the unwanted padding in text view which prevents me to align the text into the center of the circular progress bar. This is what i get.
here is my layout file:
<FrameLayout
android:id="#+id/onboarding_activity_progress_layout"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp">
<com.locationlabs.finder.android.core.ui.CircularProgressBar
android:id="#+id/onboarding_activity_progress_bar"
android:layout_gravity="center"
android:padding="10dp"
android:layout_width="120dp"
android:layout_height="120dp"
app:progressColor="#color/progress_bar_color"
app:backgroundColor="#color/progress_bar_background_color"
app:progressBarWidth="10dp"
tools:progress="60"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:includeFontPadding="false"
android:layout_gravity="center">
<TextView
android:id="#+id/number_of_remaining_steps"
style="#style/OnboardingNumberOfRemainingStepText"
tools:text="2"/>
<TextView
android:id="#+id/remaining_number_of_steps"
style="#style/OnboardingRemainingStepText"
tools:text="steps left"/>
</LinearLayout>
</FrameLayout>
Here is the styling:
<style name="OnboardingNumberOfRemainingStepText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">40sp</item>
<item name="android:textColor">#color/dark_grey</item>
<item name="android:includeFontPadding">false</item>
</style>
<style name="OnboardingRemainingStepText">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center_horizontal</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textSize">16sp</item>
<item name="android:textColor">#color/dark_grey</item>
<item name="android:textStyle">normal</item>
</style>
I was told android:includeFontPadding can help reduce the padding but it doesn't help that much. I also tried with the single textView with Spannable but I get almost the similar result. I tried with negative margin but that didn't work and it is also not reliable.
When you transfer styling attributes of a TextView to XML, TextView might render in an unexpected way. This is because the default styling for TextView is applied in a layout file which is overridden when you use style attribute in it.
You can try using parent="android:TextAppearance" in the style defined for a TextView to ensure you inherit the pre-defined styles for the TextView.
Example:
Let me know if it worked for you!
I have an EditText which I set its state to editable=false on first load like this:
<EditText
android:id="#+id/text_personalPhone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:background="#drawable/editbox_profile_style"
android:textColorHint="#4d4d4d"
android:padding="10dp"
android:layout_marginTop="5dp"
android:editable="false"
android:layout_weight="1"
android:hint="#string/user_telephone" />
When I touch a button just at its right, its state changes to editable=true.
I want to hide the bottom line of the EditText to transparent when editable=false, and I want to show the regular line when editable=true.
How can I achieve this?
with appcompat v7
overriding the value for colorControlActivated, colorControlHighlight and colorControlNormal
<style name="Theme.App" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorControlNormal">#ffffff</item>
<item name="colorControlActivated">#e6e6e6</item>
<item name="colorControlHighlight">#e6e6e6</item>
</style>
I have a simple layout:
and I want to make the EditTexts(the Views below) the same height as TextViews above. I want to avoid hardcoding height. For the TextViews I did android:minLines = 2. Unfortunately, this does not work for EditTexts. Is there a way to do this without hardcoding the height?
I am aware that this can be easily done if the EditText is to the side of the TextView in a wrap_content LinearLayout and then setting the layout_height of EditText to match_parent but, my views are in a vertical layout.
EDIT: Here is the layout of one of those columns
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_marginRight="#dimen/item_spacing"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
style="#style/TextView"
android:layout_width="match_parent"
android:layout_marginBottom="#dimen/item_spacing"
android:text="#string/xdim" />
<EditText
android:id="#+id/xdim"
style="#style/EditText"
android:layout_width="match_parent"
android:inputType="number" />
</LinearLayout>
And the styles:
<style name="TextView">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minLines">2</item>
<item name="android:gravity">center</item>
<item name="android:background">#drawable/back</item>
<item name="android:layout_gravity">center_vertical</item>
</style>
<style name="EditText" parent="#style/TextView">
<item name="android:layout_height">match_parent</item>
<item name="android:background">#drawable/item_border</item>
</style>
I have EditText in my XML as
<!-- Inside RelativeLayout -->
<EditText
android:id="#+id/edtEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/edtPhone"
android:layout_alignLeft="#id/strut"
android:layout_alignBaseline="#+id/txtLabelEmail"
android:inputType="textEmailAddress"
android:singleLine="true"
android:imeOptions="actionDone"
android:hint="#string/profile_email_hint"
style="#style/listTextValue"
android:background="#drawable/edittext_bg"
android:ellipsize="end" />
Style
<style name="listTextValue" parent="android:Widget.EditText">
<item name="android:textSize">#dimen/listTextSize</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">#color/black</item>
<item name="android:background">#drawable/edittext_bg</item>
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:singleLine">true</item>
<item name="android:ellipsize">end</item>
</style>
If I remove background attribute from EditText in Layout xml, background image will be disappeared.
If I remove ellipsize attribute from EditText in Layout xml, hint text will be expand to two lines.
As this attribute is available in Style from Eclipse's suggestion, why don't they work when put in the style?
Edit: My bad, GUI editor didn't show the background. It was another screen.
I have another layout XML with the same attributes for EditText, the background was shown correctly.
Difference between the layout would be that the first one was used inside a Fragment while the latter used directly within Activity.
This is really strange :S
I think you should try android:textAppearance="#style/your_style". It works for TextView and TextView is parent of EditText. I think it should also works.
I have a 'dialog' Activity based on the built-in Android theme Theme.Dialog:
<style name="Theme.Dialog">
<item name="android:windowFrame">#null</item>
<item name="android:windowTitleStyle">#android:style/DialogWindowTitle</item>
<item name="android:windowBackground">#android:drawable/panel_background</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="textAppearance">#android:style/TextAppearance</item>
<item name="textAppearanceInverse">#android:style/TextAppearance.Inverse</item>
<item name="textColorPrimary">#android:color/primary_text_dark</item>
<item name="textColorSecondary">#android:color/secondary_text_dark</item>
<item name="textColorTertiary">#android:color/tertiary_text_dark</item>
<item name="textColorPrimaryInverse">#android:color/primary_text_light</item>
<item name="textColorSecondaryInverse">#android:color/secondary_text_light</item>
<item name="textColorTertiaryInverse">#android:color/tertiary_text_light</item>
<item name="textColorPrimaryDisableOnly">#android:color/primary_text_dark_disable_only</item>
<item name="textColorPrimaryInverseDisableOnly">#android:color/primary_text_light_disable_only</item>
<item name="textColorPrimaryNoDisable">#android:color/primary_text_dark_nodisable</item>
<item name="textColorSecondaryNoDisable">#android:color/secondary_text_dark_nodisable</item>
<item name="textColorPrimaryInverseNoDisable">#android:color/primary_text_light_nodisable</item>
<item name="textColorSecondaryInverseNoDisable">#android:color/secondary_text_light_nodisable</item>
<item name="textColorHint">#android:color/hint_foreground_dark</item>
<item name="textColorHintInverse">#android:color/hint_foreground_light</item>
<item name="textColorSearchUrl">#android:color/search_url_text</item>
<item name="textAppearanceLarge">#android:style/TextAppearance.Large</item>
<item name="textAppearanceMedium">#android:style/TextAppearance.Medium</item>
<item name="textAppearanceSmall">#android:style/TextAppearance.Small</item>
<item name="textAppearanceLargeInverse">#android:style/TextAppearance.Large.Inverse</item>
<item name="textAppearanceMediumInverse">#android:style/TextAppearance.Medium.Inverse</item>
<item name="textAppearanceSmallInverse">#android:style/TextAppearance.Small.Inverse</item>
</style>
My layout for the Activity, I have a single EditText, a single Button and an invisible TextView I use to display messages to the user based on the validity of the EditText content:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp">
<TextView
style="#style/DialogMessage"
android:id="#+id/error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:visiblity="gone" />
<EditText
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text|textCapWords"
android:maxLength="100"
android:maxLines="1"
android:ems="20"
android:scrollHorizontally="true" />
<Button
android:id="#+id/rename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right" />
</LinearLayout>
When the user is in portrait mode, and they enter some 'bad' text in the EditText, I make the TextView visible, and populate it with an appropriate error message. This works fine, as everything shifts down, and the TextView is displayed great, even if the content spans multiple lines. Now, in landscape, when I do the same, the TextView displays fine, but the bottom element (in this case the Button) is compressed to about half it's normal height. Moving the elements around, if I put the EditText at the bottom, when the TextView is made visible, it too is compressed, and puttint the TextView at the bottom results in anything more than a single line of text being cut off.
I have tried forcing the issue after the TextView is populated by re-setting the sizes of the LinearLayout via:
LinearLayout dialog = (LinearLayout) findViewById(R.id.dialog);
dialog.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
And I have tried re-drawing the LinearLayout after the TextView is populated by calling:
LinearLayout dialog = (LinearLayout) findViewById(R.id.dialog);
dialog.invalidate();
Neither worked. Any ideas what is going on here?
Thanks,
Paul
Edit:
There is ample screen real-estate to show all three components fully... as a fully inflated TextView with the same content as I am dynamically inflating, and everything displayed fully.
Didn't figure out why this was happening, but figured out a work-around. Switching the layout to a RelativeLayout solved the issue, and everything is now displayed properly using the following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingBottom="6dp">
<EditText
android:id="#+id/inpt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text|textCapWords"
android:maxLength="100"
android:maxLines="1"
android:ems="20"
android:scrollHorizontally="true" />
<Button
android:id="#+id/btn_rename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/inpt_title"
android:layout_below="#id/inpt_title" />
<TextView
style="#style/DialogMessage"
android:id="#+id/error"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="#id/btn_rename"
android:layout_alignLeft="#id/inpt_title"
android:layout_alignRight="#id/inpt_title" />
</RelativeLayout>