I've a xamarin android application.
When I type some text in edittext and long tap on it. It shows an unexpedted context menu like this one
My styles.xml looks like
<resources>
<!-- Base application theme. -->
<style name="AppTheme">
<!-- Customize your theme here. -->
<item name="android:theme">#style/AppTheme.AppCompatLight</item>
<item name="android:actionBarStyle">#style/AppTheme.ActionBarStyle</item>
</style>
<style name="AppTheme.AppCompatLight" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#FF8B00</item>
<item name="colorPrimaryDark">#CF7100</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="colorControlNormal">#CF7100</item>
<item name="colorControlActivated">#FF8B00</item>
<item name="android:windowBackground">#color/white</item>
</style>
<style name="AppTheme.ActionBarStyle" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#FF8B00</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="Theme.App.Base" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="linkForground">
<item name="android:color">#00A4E3</item>
</style>
</resources>
Text input is
<android.support.design.widget.TextInputLayout
android:id="#+id/ui_email_text_input_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ui_address_text_input_layout">
<EditText
android:id="#+id/etUIEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:selectAllOnFocus="true"
android:gravity="start"
android:inputType="textEmailAddress"
android:hint="#string/email"
android:ems="15"/>
</android.support.design.widget.TextInputLayout>
This issue is happening on my phone. I've tested it on another phone where it just set the background of all the activities like it did for CUT and SHARE.
Help is needed to solve this issue
Related
I am using a Textinputlayout and edittext inside it, problem is when I set the error to the textinputlayout at the time of validations , it changes the color of my hint label also to red. I want to put another color instead of that red color when error comes.Only the underline color and error text should turn to red.
above shown in the pic is the problem, I dont want the email label with red color.
Below is my code.
xml file
<android.support.design.widget.TextInputLayout
android:layout_marginTop="30dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="15dp"
app:errorTextAppearance="#style/error_appearance"
app:hintTextAppearance="#style/TextLabel1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/et1"
android:padding="0dp">
<EditText
android:id="#+id/email"
android:hint="Email"
android:textColorHint="#3F4B5B"
android:maxLines="1"
android:inputType="text"
android:textSize="15sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.TextInputLayout>
#java file
#Declarations
private TextInputLayout emailerror;
private EditText Email;
#On create
Email=(EditText) findViewById(R.id.email);
emailerror=(TextInputLayout) findViewById(R.id.et1);
#Inside validation method
emailerror.setError("Enter a valid email");
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar" parent="Base.Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
TextInputLayout text color
<item name="colorControlNormal">#e0e0e0</item>
<item name="colorControlActivated">#52AF44</item>
<item name="android:textColorHint">#3F4B5B</item>
<item name="android:windowFullscreen">true</item>
</style>
<!-- <style name="error" parent="#android:style/TextAppearance">
<item name="android:textColor">#ff0000</item> <!–apply the color you wat here –>
<item name="android:textColorHint">#3E4A58</item>
<!– <item name="android:textColorHint">#3a52a6</item>–>
<!– <item name="android:textSize">12dp</item>–>
</style>-->
<!--<style name="Widget.Design.TextInputLayout" parent="AppTheme">
<item name="hintTextAppearance">#style/TextLabel1</item>
<item name="errorTextAppearance">#style/error_appearance</item>
<item name="counterTextAppearance">#style/TextAppearance.Design.Counter</item>
<item name="counterOverflowTextAppearance">#style/TextAppearance.Design.Counter.Overflow</item>
</style>-->
<style name="error_appearance" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorAccent</item>
</style>
<style name="TextLabel1" parent="TextAppearance.Design.Hint">
<item name="android:textColor">#color/colorPrimaryDark</item>
<item name="android:textSize">16sp</item>
</style>
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#color/white</item>
</style>
<style name="EditTextHint" parent="Theme.AppCompat">
<!--<item name="colorAccent">#android:color/white</item>-->
<item name="android:textColorHint">#989898</item>
<!-- <item name="colorControlNormal">#color/BackgroundtWhiteColor</item>
<item name="colorControlActivated">#color/your color</item>
<item name="colorControlHighlight">#color/BackgroundtWhiteColor</item>-->
</style>
<style name="Widget.App.Spinner" parent="#style/Widget.AppCompat.Spinner">
<item name="overlapAnchor">true</item>
<item name="android:background">#drawable/spinner_background</item>
</style>
</resources>
You need to override text input layout default style, with your customstyle.
styles.xml
<resources>
<style name="TextLabel">
<item name="android:textColorHint">#color/colorPrimary</item> <!-- Your Hint Color -->
<item name="android:textSize">18sp</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="colorControlNormal">#color/colorPrimary</item>
<item name="colorControlActivated">#color/colorPrimary</item>
</style>
<style name="error_appearance" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/colorAccent</item>
</style>
</resources>
activity_layout.xml
<android.support.design.widget.TextInputLayout
android:id="#+id/input_layout_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:theme="#style/TextLabel"
app:errorTextAppearance="#style/error_appearance">
<EditText
android:id="#+id/edt_mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_phone_iphone_black_24dp"
android:drawablePadding="8dp"
android:drawableTint="#color/colorPrimary"
android:hint="#string/email"
android:inputType="number"
android:textColor="#000" />
</android.support.design.widget.TextInputLayout>
Focused:
Without focus:
Error message:
This looks easy enough but i don't know why i'm not able to do this. This is how i want to style my button:
Resource file
<Button
android:layout_marginTop="0dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:id="#+id/buttonLogin"
android:text="Login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ButtonTheme"/>
Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="EditTextTheme">
<item name="colorControlActivated">#color/colorPrimaryDark</item>
</style>
<style name="ButtonTheme">
<item name="android:background">#color/colorPrimary</item>
<item name="android:textColor">#color/colorWhite</item>
</style>
</resources>
But somehow the background color is still default which is grey although the text has already change color to white.
Why did this happen? And how i can overcome this? Thank you in advance.
Instead of
android:theme="#style/ButtonTheme"
Do
style="#style/ButtonTheme"
on your <Button>
I found out that in my app colours are set in res/values/themes.xml so I deleted the styles.xml I created and continued with changes in themes.xml. This worked for me. No styles.xml needed.
I am using TextInputEditText in my registration screen. I am able to set the style of floating label. I want to set the custom font on hint and text of TextInputEditText using style. Does anyone know whats way of it ?
<android.support.design.widget.TextInputLayout
android:id="#+id/til_registration_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:paddingEnd="#dimen/default_view_padding_right_8dp"
android:paddingStart="#dimen/default_view_padding_left_8dp"
android:textColorHint="#color/colorSecondaryText"
app:hintTextAppearance="#style/AppTheme.InputLayoutStyle"
app:layout_constraintTop_toBottomOf="#id/textview_registration_title">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/registration_name"
android:imeOptions="actionNext"
android:singleLine="true"
android:textColor="#color/colorPrimaryText" />
</android.support.design.widget.TextInputLayout>
styles.xml
<style name="AppTheme.InputLayoutStyle" parent="TextAppearance.AppCompat">
<item name="android:textColor">#color/colorPrimary</item>
<item name="fontFamily">#font/lato_light</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
<item name="buttonStyle">#style/AppTheme.Button</item>
</style>
I want to set style for entire application.
Old question but worth to answer.
Just set the "textInputStyle" to style the TextInputLayouts and "editTextStyle" to style the TextInputEditTexts in your app theme.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
<item name="buttonStyle">#style/AppTheme.Button</item>
<item name="textInputStyle">
#style/MyCustomTextInputStyle
</item>
<item name="editTextStyle">
#style/MyCustomEditTextStyle
</item>
</style>
<style name="MyCustomTextInputStyle" parent="Widget.Design.TextInputLayout">
<item name="android:textColorHint">#color/colorSecondaryText</item>
<item name="hintTextAppearance">#style/any_style_you_may_want"</item>
</style>
<style name="MyCustomEditTextStyle" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#color/colorPrimary</item>
<item name="fontFamily">#font/lato_light</item>
</style>
This will apply the same style to all TextInputLayout and TextInputEditText in you application.
I have so specific problem. I'm applying theme for all textviews. It appears on preview but when I run this app on phone I face with unstyled textview. The styles I set for other views are working. only textviewstyle is not working.
In this sample textview color is green in preview but when i run it on phone its black. Why?
style.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:textViewStyle">#style/myTextViewStyle</item>
<item name="android:buttonStyle">#style/myButtonStyle</item>
<item name="android:editTextStyle">#style/myEditTextStyle</item>
<!-- Customize your theme here. -->
</style>
<style name="myTextViewStyle" parent="#android:style/Widget.TextView">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">24sp</item>
</style>
<style name="myButtonStyle" parent="#android:style/Widget.Button">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">24sp</item>
</style>
<style name="myEditTextStyle" parent="#android:style/Widget.EditText">
<item name="android:textColor">#00ff00</item>
<item name="android:textSize">24sp</item>
</style>
activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="edit text" />
"textViewStyle" is not defined in v22.1.1. You can find more detail from the link:
https://code.google.com/p/android/issues/detail?id=170476
I've define a Style for the button
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fontFamily">sans-serif</item>
<item name="android:windowBackground">#color/background</item>
<item name="android:buttonStyle">#style/AppTheme.Button</item>
<item name="android:textViewStyle">#style/AppTheme.TextView</item>
<item name="android:editTextStyle">#style/AppTheme.EditText</item>
<item name="android:checkboxStyle">#style/AppTheme.CheckBox</item>
</style>
button style:
<style name="AppTheme.Button" parent="android:Widget.Button">
<item name="android:background">#drawable/button_background</item>
<item name="android:textColor">#color/white</item>
<item name="android:textSize">#dimen/normal_text</item>
</style>
I can see it properly on the Android Studio preview, but doesn't work on device. It works on device if I set it in the element inside the layout.
<Button
android:id="#+id/btn_login"
style="#style/AppTheme.Button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="LOGIN"/>
I just want to define it in the AppTheme
It's a bug, they will fix it in the new release of the AppCompat.
More info: https://code.google.com/p/android/issues/detail?id=170476