I have a spinner after i loaded data into it. the style is not as my expected.
Spinner code
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/spinnerGender"
android:spinnerMode="dropdown"
android:layout_marginLeft="-5dp"
android:layout_marginTop="5dp"/>
Current style.
My expected
How can i change theme/style the spinner
try this,
<Spinner
android:id="#+id/spinnerGender"
style="#android:style/Widget.Holo.Light.Spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="-5dp"
android:layout_marginTop="5dp"
android:spinnerMode="dropdown" />
otherwise you can create custome style and use
Example at following link:
http://androidopentutorials.com/android-how-to-get-holo-spinner-theme-in-android-2-x/
Another approach is using the styles.xml file
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:spinnerStyle">#android:style/Widget.Holo.Light.Spinner</item>
</style>
Related
I'm new to android development and I am designing an app in which I use a custom Action Bar from a layout xml file. I had done with the following code and successfully got the layout into action bar. But the problem I am getting is extra space on left and right side of the Action Bar.
I'm using the following codes.
// java code
public class SimpleQns extends AppCompatActivity{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.questions);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.actionbar_qns);
//other codes for app }
xml layout file with name actionbar_qns.xml
<?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:weightSum="5"
android:background="#drawable/actionbar_qns"
android:padding="0dp"
android:layout_margin="0dp">
<Button
android:id="#+id/play"
android:layout_width="50dp"
android:layout_weight="1"
android:layout_height="50dp"
android:layout_gravity="center"
android:text="P"
/>
<TextView
android:id="#+id/tv_actionbar_questions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:layout_gravity="center"
android:gravity="center"
android:text="Simple Questions"
android:textColor="#color/white"
android:textSize="20sp" />
<Button
android:id="#+id/stop"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="center"
android:text="S" />
</LinearLayout>
Style.xml file
<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>
</resources>
How can I remove the extra space in Action Bar..?
If you want more customization on ActionBar, Use the ToolBar as an Actionbar which is more customizable than the default ActionBar.
ActionBar contains a default padding in itself. Add this line to your ActionBar xml to remove the default padding:
android:padding="0dp"
I am setting style,color and size to textview , that is working
this is my code `
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="#000"
android:textSize="14sp"
android:textStyle="italic"/>
Please check your parent layout is correct some times transparent layer or such things create visualise problem with colour
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_agent_code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="10dp"
android:gravity="center"
android:text="AppCompatTextView"
android:textColor="#FFFFFF"
android:textSize="114dp"
android:textStyle="italic" />
Use Dimension for setting up a text size ,always avoid hard coding
If you want to set same style for text-color,text-size and text-style than you can create something like
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textStyle">italic</item>
</style>
i want to change bottom line color of below MaterialBetterSpinner Spinner please help..
<com.weiwangcn.betterspinner.library.material.MaterialBetterSpinner
android:id="#+id/spUserType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:hint="Select a Option"
android:paddingLeft="0dp"
app:met_floatingLabel="normal"
app:met_textColorHint="#757575"/>
Try this
styles.xml
<style name="ThemeSpinner">
<!-- Color when pressed -->
<item name="colorAccent">#ffa000</item>
<!-- Default color for the dropdown arrow and line -->
<item name="colorControlNormal">#ffc107</item>
</style>
layout.xml
<Spinner
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeSpinner" />
Edittext setError method is not showing text in android 6.0 but working perfectly in android 5.0. I have tried many solutions but don't get solution and i tried all solution of Android 6 EditText.setError not working correctly, So how to fix this issue?
This is my xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar_create_page"
android:fillViewport="false">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="match_parent"
android:layout_height="180dp"
android:id="#+id/ivPageBanner"
android:src="#drawable/bg_timeline"
android:scaleType="fitXY" />
<ImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:id="#+id/ivPageDp"
android:layout_alignParentBottom="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="140dp"
android:layout_marginLeft="15dp"
android:src="#drawable/flagwithcamera" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/etPageName"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/ivPageDp"
android:layout_marginTop="20dp"
android:hint="Page name"
style="#style/EditTextTheme"
android:theme="#style/EditTextTheme"
android:textCursorDrawable="#drawable/black_cursor"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:textColorHint="#color/hint_foreground_material_light" />
</RelativeLayout>
</ScrollView>
Here is my style for Edittext:
<style name="EditTextTheme" parent="Widget.AppCompat.EditText">
<item name="android:textColor">#color/transparent</item>
<item name="android:textColorHint">#color/transparent</item>
<item name="colorAccent">#color/colorPrimary</item>
<item name="colorControlNormal">#color/colorPrimary</item>
<item name="colorControlActivated">#color/colorPrimary</item>
</style>
and here is my Colors.xml:
<color name="colorPrimary">#64100b</color>
<color name="transparent">#fc000000</color>
I got my solution. Just removed this from my Edittext:
android:theme="#style/EditTextTheme"
Reason is underline below text of setError.
Alright, but where are these underlines come from?
android:theme is an attribute of View and when you set a style as android:theme, that style will be wrapped by ContextThemeWrapper with context theme while in inflation of view.
So that means, if you set android:theme property with style that contains android:background item like
<item name="android:background">#color/red</item>
every child view of this theme owner will be have a green background.
"Widget.AppCompat.EditText" is a style and references ?attr/editTextBackground as a "android:background". And in v21/values-21.xml file #drawable/abc_edit_text_material is defined as editTextBackground.
Thanks to https://stackoverflow.com/a/42355788/5909385
I think, It does showing but it is bit chopped off. Try using Floating Labels & Set Error to TextInputLayout reference. Please let me know if you still facing issue
All of my searches has led me to guides on how to change the text color of the spinner choices, but how do I change the color of the text and arrow on the spinner itself?
Here's a snip of my spinner. It's supposed to say "Mercury".
Here's my attempt at the style. It did change the arrow to white, but not the text. I only applied it to the spinner since it will mess up the rest of the activity.
<style name="Theme.LightText2" parent="AppTheme">
<item name="android:editTextColor">#ffffff</item>
<item name="android:textColorPrimary">#ffffff</item>
<item name="android:textColorSecondary">#ffffff</item>
<item name="android:textColorTertiary">#ffffff</item>
<item name="android:textColorPrimaryInverse">#ffffff</item>
<item name="android:textColorSecondaryInverse">#ffffff</item>
<item name="android:textColorTertiaryInverse">#ffffff</item>
</style>
UPDATE: I tried to apply it to the activity itself via the manifest and it worked, but it's messed up the rest of my activity.
If you want to achieve this do one thing , Take one textview and set arrow icon on right(Drawableright) customize your text text view as you wont and on click open dialog with single selection and on item selected set text to textview
Try like this and use spnrSelect.performClick(); on click of rlSpinner to open spinner
<RelativeLayout
android:id="#+id/rlSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/scale_20dp"
android:layout_marginRight="#dimen/scale_20dp"
android:layout_marginTop="#dimen/scale_1dp"
android:background="#null"
android:clickable="true">
<Spinner
android:id="#+id/spnrSelect"
android:layout_width="match_parent"
android:layout_height="0dp"
android:clickable="true"
android:dropDownWidth="#dimen/scale_300dp"
android:scrollbars="none"
android:spinnerMode="dropdown" />
<TextView
android:id="#+id/txtSelect"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingBottom="#dimen/scale_1dp"
android:paddingRight="#dimen/scale_1dp"
android:paddingTop="#dimen/scale_1dp"
android:text="#string/txtSelect"
android:textColor="#color/edt_hint"
android:textColorHint="#color/edt_hint"
android:textSize="#dimen/txt_12" />
<ImageView
android:id="#+id/spnrDownArrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="#dimen/scale_10dp"
android:background="#drawable/arrow_icon"
android:rotation="90" />
</RelativeLayout>
Create array adapter which will inflate TextView from Layout_resource
then set your color to inflated TextView
your_spinnersp.setAdapter(new ArrayAdapter<>(context,R.layout.txt_spinner,lst_data));
in layout add TextView
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:padding="8dp" android:textSize="16sp"
android:background="#ff0000"
android :textColor="#ffff00"
android:layout_width="match_parent" android:layout_height="wrap_content"/>