I have the following preference screen in my app
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
<EditTextPreference
android:key="edittexvalue"
android:id="#+id/edittextvalue"
android:title="Title Here"
android:summary="Summary Here"
android:defaultValue="Some Value"/>
<Preference
android:key="customPref"
android:title="Title Here"
android:summary="Summary Here"/>
</PreferenceScreen>
All of that works just fine however my app i have custom backgrounds and text colors/sizes but i can't figure out how to format the PreferenceScreen I assume you point this at another xml? but can't figure out the code i need and what changes should be made. The main concern is the background color the text is fine i guess but the background just doesn't match the rest of my app. So i'd like to set a custom background color lets say red for now (#ff0000)
I thank anyone that can help me with this problem
You can to apply a theme to it in your manifest, for example
<activity android:name=".Settings"
android:theme="#style/YourStyle"/>
and in your styles.xml (if you dont have one, create it in the values folder)
you can modify whatever you need
For example
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="YourStyle" parent="android:Theme.Light">
<item name="android:listViewStyle">#style/Widget.ListView</item>
<item name="android:windowNoTitle">true</item>
</style>
<style name="Widget" parent="android:Widget">
</style>
<style name="Widget.ListView">
<item name="android:background">#color/white</item>
<item name="android:divider">#color/gray_division</item>
<item name="android:dividerHeight">2dip</item>
</style>
</resources>
I hope this helps
Related
Styles.xml:
<style name="windowTitleBackgroundStyle">
<item name="android:background">#A4D05F</item>
</style>
<style name="windowTitleStyle">
<item name="android:drawableLeft">#drawable/smartlogo</item>
<item name="android:textColor">#C6C09C</item>
<item name="android:padding">12dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
I am customizing my titlebar in android using eclipse ide. I can also see my image that is being set by the drawableleft, however it is too big. Do you know how to set the width and size of the drawableleft?
you can use a xml-drawable, that you can customise as you wish.
You can find here some examples and a lot others on net.
Alternatively, you can also create a simple XML, containing a view, image etc, like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="#drawable/icon"
android:width="#dimen/icon_size"
android:height="#dimen/icon_size"
/>
</layer-list >
,and use this as your drawableLeft.
Hope this helps!
if API level 23 and higher you can change like this
<item
name="android:drawableLeft"
android:drawable="#drawable/smartlogo"
android:height="24dp"
android:width="24dp"/>
As much as I learn, I still have a long way to go ...
I'm trying to use Facebook SDK to provide details for a sign up.
I am using a blue, yellow and white theme for my app; the text being white. My style setup is:
<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">#android:color/holo_orange_light</item>
<item name="android:colorBackground">#color/colorMainBackground</item>
<!--<item name="android:actionBarStyle">#style/ThemeActionBar</item>-->
<!--<item name="android:windowActionBarOverlay">true</item>-->
<item name="android:textColor">#android:color/white</item>
<item name="android:textColorLink">#android:color/holo_orange_light</item>
<!-- Support library compatibility -->
<!--<item name="actionBarStyle">#style/ThemeActionBar</item>-->
<!--<item name="windowActionBarOverlay">true</item>-->
<item name="android:textColorPrimary">#android:color/white</item>
<item name="android:titleTextColor">#color/yellow</item>
<item name="android:textColorPrimaryInverse">#android:color/black</item>
<item name="android:navigationBarColor">?android:attr/statusBarColor</item>
<item name="android:textColorSecondary">#android:color/white</item>
</style>
However, when Facebook shows a dialog box, all I get is a white square:
It would appear that Facebook are using my textcolor and hence the white box. Is there a way I can override this? Or have Facebook use the default colour scheme (if there is one).
This is somewhat frustrating me now.
My Manifest entry for Facebook is:
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="#string/app_name" />
Thanks in advance
Facing the same issue. It seems FacebookActivity picks up the color from the style you declared in the application tag.
<application
...
android:theme="#style/AppTheme'>
You see it white because in styles.xml you have the accent color to white. for your theme.
<item name="colorAccent">#FFF</item>
Since in my application I need the colorAccent to be another color, I chose to have two AppThemes. One for my activities with whatever colorAccent I need and one for the application that will get used by Facebook.
I tried to add a theme to com.facebook.FacebookActivity but it gets ignored. Something to do with ManifestMerging.
I am using an astuetz sliding tab strip in my android application, and I cannot seem to figure out how to get rid of the blue highlight that appears when you are selecting a tab. I have provided a picture below to illustrate the problem. Any suggestions would be greatly appreciated!
That library uses this drawable as a background:
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="#android:integer/config_shortAnimTime">
<item android:state_pressed="true" android:drawable="#color/background_tab_pressed" />
<item android:state_focused="true" android:drawable="#color/background_tab_pressed"/>
<item android:drawable="#android:color/transparent"/>
</selector>
where the color is:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="background_tab_pressed">#6633B5E5</color>
</resources>
So you can create your own selector with your favorite color.
My theme is:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowContentOverlay">#null</item>
<item name="actionBarTheme">#style/MyActionBarTheme</item>
<item name="actionBarStyle">#style/MyActionBarStyle</item>
<item name="circularProgressBarStyle">#style/CircularProgressBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/white</item>
<item name="actionBarTabBarStyle">#style/MyActionBarTab</item>
</style>
I don't see any style here that can affect my button text color because they are for action bar styling. But I still cannot change my button text color in layout file:
<Button
...
android:textSize="22sp"
android:textColor="#color/yellow"
... />
I can change textSize here but not the textColor. Anyone can tell me why? Shouldn't it be the highest priority for styling? (That means overriding style.xml config if there is one). Please correct me if I am wrong. Much appreciation!
This is what you should be doing:
android:textColor="#android:color/yellow"
instead of
android:textColor="#color/yellow"
button.setTextColor(getApplication().getResources().getColor(R.color.green));
button.setTextColor(Color.parseColor("#ff1100"));
add this into your style
<item name="colorButtonNormal">#color/colorPrimary</item>
or
you can add property android:background to button class like this
<Button
...
android:textSize="22sp"
android:background="#color/yellow"
... />
As TejjD said :
This is what you should be doing:
android:textColor="#android:color/yellow" instead of
android:textColor="#color/yellow"
You have to define your custom color in Colors.xml file.
I'd like to change the background for an image button. Basically the image I have looks great on a transparent background and a bit lousy when there are a bunch of them all with a non-transparent background.
This should be easy - just change the android:background on the button to a transparent color (via a drawable):
click_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"><color android:color="#FF008080" />
</item>
<item android:state_pressed="true"><color android:color="#FF008080" />
</item>
<item><color android:color="#00000000" />
</item>
</selector>
Then the button
<ImageButton
android:id="#+id/players"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="#drawable/click_background"
android:contentDescription="#string/players"
android:src="#drawable/speaker_tile" />
The problem is that I actually want to retain the state_focussed and state_pressed versions of the background (which I presume is derived from the theme). I would like to have the background appear when the button is pressed or selected (and appear with the exact same colour/drawable) that would be used by the theme normally when a button is pressed would be helpful.
I was wondering if there is a way to do one of the following, but have so far been unable to find anything on either:
Define a selector that in some what inherits from another (similar to the way a theme can inherit from another).
Create an entirely new selector but have it's XML reference the color/drawable of the theme's state_focussed and state_pressed used for an image button. Edit: It looks like this option is out. I would have needed attributes, but you can't reference them from a drawable. See here
I'd like to do this in Declarative XML rather than Programmatic Java if possible.
You can copy the drawables used by the Android OS into your project and use them in your state-list drawable. You can find the images in {android-sdk-directory}/platforms/android-##/data/res/drawable[-*dpi]
EDIT:
If you go to {android-sdk-directory}/platforms/android-##/data/res/values, you'll find the themes.xml and styles.xml files used by Android. Using them you can figure out which drawables you'll be looking for.
For example, the default theme on newer versions of Android is Theme.Holo. This theme has a default style for ImageButtons declared like so:
<item name="imageButtonStyle">#android:style/Widget.Holo.ImageButton</item>
In styles.xml, this style is defined as follows:
<style name="Widget.Holo.ImageButton" parent="Widget.ImageButton">
<item name="android:background">#android:drawable/btn_default_holo_dark</item>
</style>
Thankfully the background attribute is right there defined in plain sight. Sometimes it's inherited from a parent style and you have to find that instead. In any case, here's the drawable (found in the /drawable directory since it's xml):
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="#drawable/btn_default_normal_holo_dark" />
<item android:state_window_focused="false" android:state_enabled="false"
android:drawable="#drawable/btn_default_disabled_holo_dark" />
<item android:state_pressed="true"
android:drawable="#drawable/btn_default_pressed_holo_dark" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="#drawable/btn_default_focused_holo_dark" />
<item android:state_enabled="true"
android:drawable="#drawable/btn_default_normal_holo_dark" />
<item android:state_focused="true"
android:drawable="#drawable/btn_default_disabled_focused_holo_dark" />
<item
android:drawable="#drawable/btn_default_disabled_holo_dark" />
</selector>
So those are the drawables Android uses for the background of a standard ImageButton in the default (holo dark) theme.