Android Preference Fragment Text Color - android

I want to change the text color in android preferences fragment. I am currently using a custom theme to change the checkbox image, background, onClick highlighting and it all works great...besides the text color. I don't want to use a default theme, I want to have my own theme so it all looks how I want to but just change the text color, can someone please help.
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="selectedTextStyle">
<item name="android:textSize">18sp</item>
</style>
<style name="buttonTextStyle">
<item name="android:textSize">20sp</item>
</style>
<style name="PreferencesTheme" >
<item name="android:windowBackground">#drawable/lists_background</item>
<item name="android:listViewStyle">#style/listViewPrefs</item>
<item name="android:checkboxStyle">#style/MyCheckbox</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance">
<item name="android:textColor">#color/black</item>
</style>
<style name="listViewPrefs" parent="#android:Widget.ListView">
<item name="android:listSelector">#layout/list_selector_master</item>
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyCheckbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/btn_check</item>
</style>
</resources>
Manifest:
<activity
android:name="com.package.SettingsActivity"
android:theme="#style/PreferencesTheme"
android:configChanges="keyboard|orientation" >
</activity>
Activity:
import android.app.Activity;
import android.os.Bundle;
import android.preference.PreferenceFragment;
public class SettingsActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Display the fragment as the main content.
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.commit();
}
public static class SettingsFragment extends PreferenceFragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.preferences);
}
}
}

Here are the two TextView objects from preference.xml (layout for a Preference):
<TextView android:id="#+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="#+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/title"
android:layout_alignLeft="#android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
So looks like you can override textAppearanceLarge and textColorSecondary in your theme to achieve a color change. Here's an example:
<style name="AppTheme">
<item name="android:textAppearanceLarge">#style/MyTextAppearance</item>
<item name="android:checkboxStyle">#style/MyCheckBox</item>
</style>
<style name="MyCheckBox" parent="#android:style/Widget.CompoundButton.CheckBox">
<item name="android:button">#android:drawable/btn_star</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.Large">
<item name="android:textColor">#ff0000</item>
</style>

I think an easy and clear way to do that is next:
res/values/styles.xml
<style name="SettingsFragmentStyle">
<item name="android:textColorSecondary">#222</item>
<item name="android:textColor">#CCC</item>
<item name="android:background">#999</item>
...
</style>
In the Activity that contains PreferenceFragment subclass inside onCreate:
setTheme(R.style.SettingsFragmentStyle);

Just found an answer that gets the job done.
This file is default layout for the preference list item:
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2006 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- Layout for a Preference in a PreferenceActivity. The
Preference is able to place a specific widget for its particular
type in the "widget_frame" layout. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingRight="?android:attr/scrollbarSize"
android:background="?android:attr/selectableItemBackground" >
<ImageView
android:id="#+android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dip"
android:layout_marginRight="6dip"
android:layout_marginTop="6dip"
android:layout_marginBottom="6dip"
android:layout_weight="1">
<TextView android:id="#+android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceLarge"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView android:id="#+android:id/summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#android:id/title"
android:layout_alignLeft="#android:id/title"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorSecondary"
android:maxLines="4" />
</RelativeLayout>
<!-- Preference should place its actual preference widget here. -->
<LinearLayout android:id="#+android:id/widget_frame"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" />
</LinearLayout>
You can use it as base and create your own custom layout. This layout must be applied within each Preference like this
<Preference android:key="somekey"
android:title="Title"
android:summary="Summary"
android:layout="#layout/custom_preference_layout"/>
You can change the whole layout outside the list, you just need to have a layout file that contains a listview where the preferences will be populated like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Something" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
To override the default layout for the PreferenceFragment, override the method onCreateView and change the inflated view:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.custom_options_layout, null);
}
Based off these answers:
Creating a custom layout for preferences
How to add a button to PreferenceScreen
Android: How to adjust Margin/Padding in Preference?

To me nothing of the above methods didn't work. I ended up extending Prefernces class of the kind I used, in my case CheckBoxPrefernces:
public class MyPreferenceCheckBox extends CheckBoxPreference {
public MyPreferenceCheckBox(Context context) {
super(context);
}
public MyPreferenceCheckBox(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyPreferenceCheckBox(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
#Override
protected View onCreateView(ViewGroup parent) {
ViewGroup root = (ViewGroup) super.onCreateView(parent);
((TextView)root.findViewById(android.R.id.title)).setTextColor(parent.getResources().getColor(R.color.red));
((TextView)root.findViewById(android.R.id.summary)).setTextColor(parent.getResources().getColor(R.color.red));
return root;
}
}
And the use in the prefs.xml:
<com.my.package.name.MyPreferenceCheckBox
android:title="#string/my_title"
android:defaultValue="true"
android:key="#string/my_key"
android:summary="On/Off" />
This answer showed me that path:

Haven't got enough rep to comment or upvote, but I just wanted to add that mharper's suggestion about TextAppearanceMedium also worked for me in regards to changing the text colour. If somebody knows why this is, please do explain it.
So just adjust the accepted answer like so:
<style name="AppTheme">
<item name="android:textAppearanceMedium">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#ff0000</item>
</style>
At least if nobody can explain why this is, it might stop somebody having the same difficulty I did trying to change the text colour.

I was able to change text color in PreferenceFragment with this:
styles.xml
<resources>
<style name="SettingsTheme" parent="android:Theme.Holo">
<item name="android:textColorPrimary">#color/light_blue_font_color</item>
<item name="android:textColorSecondary">#color/white_font_color</item>
<item name="android:textColorTertiary">#color/white_font_color</item>
</style>
</resources>
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="light_blue_font_color">#33b5e5 </color>
<color name="white_font_color">#ffffff </color>
</resources>
AndroidManifest.xml
<activity
android:name="xx.yy.zz.SettingsActivity"
android:theme="#style/SettingsTheme" >
</activity>

If you're using compat library, just add:
<item name="colorAccent">#ff0000</item>
to your style

I work with min API 11 and compile whith 23.
set theme and after set background for this theme.
if you work with > API 14 you can use Theme_DeviceDefault.
This is the simplest solution I find :
public static class SettingsFragment extends PreferenceFragment {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActivity().setTheme(android.R.style.Theme_Holo);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.settings);
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
if(view != null){
view.setBackgroundColor(ContextCompat.getColor(getActivity(), android.R.color.background_dark));
}
}
}

Related

Change Text color depending on Theme

How do i change the text color depending on the theme in Android Studio with setTextColor()?
So that when dark mode is enabled it changes the Text to white and when white mode is enabled it changes to black
this may be not exactly what you want but it might help you.
it doesn't matter what layout you use i'm just going to provide dummy code so you can understand.
Blockquote
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:text="Dark theme text"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_gravity="center"
android:textColor="#color/colorPrimaryDark"
android:text="Dummy text"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
note : In order to change the color depending upon the current theme light or dark, it has to be dynamic.
now implement Dark theme:
create a new resource file and call attributes.xml, inside this file we will be declaring some attributes that we need for setting colors for widgets and layout.
and think of these attributes as controllers for colors in our layout.
add this snippet to attributes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="metaColor" format="color"/>
<attr name="color" format="color"/>
<attr name="textColor" format="color"/>
</resources>
After that, we need to create two theme, light and dark in styles.xml file
inside styles.xml, here we make use of our attributes, add this code snippet:
<style name="Light" parent="AppTheme">
<item name="textColor">#000000</item>
<item name="metaColor">#606060</item>
<item name="color">#ffffff</item>
</style>
<style name="Dark" parent="AppTheme">
<item name="textColor">#ffffff</item>
<item name="metaColor">#aeaeae</item>
<item name="color">#000000</item>
</style>
then go to activity_main.xml
update it with this code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18sp"
android:textColor="?attributes/textColor"
android:text="Dark theme text"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="?attributes/metaColor"
android:text="Dummy text"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
now go to MainActivity and add this inside of onCreate function like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Dark);
setContentView(R.layout.activity_main);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.Light);
setContentView(R.layout.activity_main);
}
and here is a really cool repository to use to create your custom themes and change them dynamically with ripple animation:
https://github.com/imandolatkia/Android-Animated-Theme-Manager

android set custom attributes in styles.xml and get in program

I am trying to get a button custom attribute to return true/false using custom attributes defined in styles.xml. My example is trivial with only two buttons but I can't get it to work.
My layout looks like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CustomAttr">
<Button
android:id="#+id/button_1"
style="#style/red_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1!" />
<Button
android:id="#+id/button_2"
style="#style/blue_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 2!" />
</LinearLayout>
<resources>
styles.xml looks like:
<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>
<attr name="is_red" format="boolean"/>
<style name="red_button" >
<item name="android:background">#ffff0000</item>
<item name="is_red">true</item>
</style>
<style name="blue_button" >
<item name="android:background">#ff0000ff</item>
<item name="is_red">false</item>
</style>
</resources>
And the code looks like:
public class CustomAttr
extends AppCompatActivity
implements View.OnClickListener {
private static final String TAG =
CustomAttr.class.getSimpleName();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_attr);
findViewById(R.id.button_1)
.setOnClickListener(this);
findViewById(R.id.button_2)
.setOnClickListener(this);
}
#Override
public void onClick(View v) {
int id = v.getId();
int [] searchAttr = {R.attr.is_red};
TypedArray attrs
= v.getContext()
.obtainStyledAttributes(null, searchAttr);
boolean isRed = attrs.getBoolean(0, false);
Log.d(TAG, String.format("%s:%b"
, (id == R.id.button_1) ? "button 1" : "button 2"
, isRed )
);
}
}
Everything compiles fine and the button colors are working and I'm not getting any warnings. But the boolean isRed in the onClick method always returns false.
I've been looking through the net and docs all day and this looks like it should work -- but it doesn't. What am I doing wrong?
Thanks
Steve S.
********* EDIT Fri Sep 21 10:17:01 PDT 2018 *********
As noted below, this is a prototype for an app with about 250 different buttons in a gridview. There are about 250 of basicly 4 different types and I can set almost everything in each button using one of 4 different styles. I was already using the tag and text fields and really needed a way to detect the button's type (1 0f 4). I finally created a custom button view with it's own attribute set. The code for the working prototype custom view button with its attribute on github. Thanks!
Steve S.
You haven't used the is_red attribute in your xml. Something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".CustomAttr">
<Button
android:id="#+id/button_1"
custom:is_red="true"
style="#style/red_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 1!" />
<Button
android:id="#+id/button_2"
custom:is_red="false"
style="#style/blue_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button 2!" />
</LinearLayout>

how to delete the toolbar in android design

The red frame should not have in my code, but after I updated my Android Studio, it is showed in all of my APPS. please click and see the picture.
How to delete the red frame from my code? And it could not find in its design/text. The blue frame's begin code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/activity_login_user_email_edt"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="35dp"
android:autoText="true"
android:hint="e-mail" />
The Answer Skynet posted is correct,but this is the programatical way
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Full Screen and remove toolbar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
That is the theme your activity is extending from. You change it in the styles.xml. Then you need to update this setting in the Manifest.
You need to add this to styles.xml:
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Then in your AndroidManifest.xml for this Activity:
<activity
android:name=".YourActivity"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
</activity>
The above will work if you are extending from AppCompatActivity which should look like:
public class YourActivity extends AppCompatActivity{}

Applying Checkbox Styles in Android PreferenceActivity

I am writing an application that SDK 10+. I would like all of my check boxes in my Activities as well as my PreferenceActivity to look the same. I created a Theme that has a Theme.Black parent. I created a child style of android:Widget.CompoundButton.CheckBox and set the android:checkboxStyle to that child theme. I have applied my theme across the entire app in the application manifest element with:
android:theme="#style/AppTheme"
When I look at the main Activity, the check box style has been applied as expected, but the checkbox in the PreferenceActivity does not have the style. My questions are:
Is it possible to style minor parts of preferences without having to specify an entire new layout for each one?
More generally, I would like to do this for other controls that show up in the preferences, like toggles or switches. Is that possible? (My guess is that the solution to one will pretty much be able to be applied to those particular issues as well)
I know there is an issue for nested preferences, but this question is applicable to Preferences at the top level. Any help is greatly appreciated. I have been banging my head against a wall on this one for a couple hours now...
Here is what I have so far:
prefs.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="checkbox1"
android:summary="This is a themed checkbox preference"
android:title="Checkbox 1" />
</PreferenceScreen>
ThemedPreferenceActivity.java
public class ThemedPreferencesActivity extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
main.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:orientation="vertical" >
<CheckBox
android:id="#+id/checkBox1"
android:text="CheckBox"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" style="#style/AppTheme.Preference.Checkbox" />
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Black">
<item name="android:checkboxStyle">#style/AppTheme.Preference.Checkbox</item>
</style>
<style name="AppTheme.Preference.Checkbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/pref_checkbox</item>
<item name="android:background">#FF0000</item>
</style>
</resources>
pref_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="#android:drawable/ic_menu_call" />
<item android:state_checked="false" android:drawable="#android:drawable/ic_menu_camera" />
</selector>
Looks like the issue was with the line:
<style name="AppTheme.Preference.Checkbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/pref_checkbox</item>
<item name="android:background">#FF0000</item> <---- RIGHT HERE
</style>
Looks like specifying that was causing the check box to misbehave. Turns out that I didn't need that anyway (and in fact, realized I would do it in the "ListView" style anyway if I wanted it) so, problem solved.

Custom title bar issue

I set a custom title bar as example http://coderzheaven.com/2011/06/custom-title-bar-in-android/ , every thing works fine but still blue frame appear from original title . The only thing I added is to set the background color to custom title as (android:background="#EECBAD"). How can I remove this blue frame?
###custom_title.xml:
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EECBAD"
xmlns:android="http://schemas.android.com/apk/res/android">
<ImageView
android:layout_width="40dip"
android:id="#+id/ImageView01"
android:background="#drawable/ic_launcher"
android:layout_height="40dip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tv"
android:text="ELNABIH"
android:layout_toRightOf="#+id/ImageView01"
android:textColor="#drawable/red"
android:textStyle="bold"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip" />
</RelativeLayout>
java.class
package com.test.list;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.widget.TextView;
public class Tttt extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Boolean customTitleSupported = requestWindowFeature
(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
if (customTitleSupported) {
getWindow().setFeatureInt
(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title);
TextView tv = (TextView) findViewById(R.id.tv);
tv.setText("name");
}
}
}
Brother, I think this link would help you for sure. I think you'll have to define styles and themes in xml too.
Please create styles.xml & themes.xml in values folder folder under res. Write the following code :
Code for styles.xml
<?xml version="1.0" encoding="UTF-8"?>
<resources> <style name="WindowTitleBackground" parent="android:Theme">
<item name="android:background">#android:color/background_dark</item>
</style>
</resources>
Code for themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme">
<item name="android:windowTitleSize">54px</item>
<item name="android:windowTitleBackgroundStyle">#style/WindowTitleBackground</item>
</style>
</resources>
and insert this in your manifest - android:theme="#style/MyTheme"
Try to override "android:windowTitleBackgroundStyle".
If you set the background color for tv TextView, it's because it also has some right and left padding, beside being set to wrap_content:
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
You can remove those lines, or try to set the background color for the parent, RelativeLayout01
put on style.xml:
<style name="CustomWindowTitleBackground">
<item name="android:background">#color/LightFacebook</item>
</style>
on #color/LightFacebook use u custom color.
You should hide the default title first. You should declare that in AndroidManifest.xml for the activity or set the window params in the java code.
<activity
android:name=".MainActivity"
android:theme="#android:style/Theme.Black.NoTitleBar" />

Categories

Resources