The application I'm developing has several lists of items (including one in NavigationDrawer, one in a dialog, etc).
When the user press one item on the list on pre-lollipop smartphones, the background changes to a light blue color (including preferences on PreferenceActivity). On lollipop devices, however, the background changes to a light grey color with a beautiful ripple effect. What I want is to have the same light grey color for all devices (the ripple effect is not needed).
I've seem some posts of people styling ListView items setting backgrounds, but I need an approach to style all of them at once.
ps: my app uses Theme.AppCompat.Light.NoActionBar as base theme.
Create a file res/drawable/listitem_background.xml with the following content :
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_activated="true" android:drawable="#color/purple_dark" />
<item android:drawable="#android:color/transparent" />
</selector>
Replace the #color/purple_dark with the color of your choice.
Then, in your theme, add the following line :
<item name="android:activatedBackgroundIndicator">#drawable/listitem_background</item>
EDIT:
To mantain the lollipop effects and colors instead of placing the theme in the values folder, place it in the values-v22
Define a style resource file like this one
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyTheme" parent="android:Theme.AppCompat.Light.NoActionBar">
<item name="android:listViewStyle">#style/MyListViewStyle</item>
</style>
<style name="MyListViewStyle" parent="android:Widget.ListView">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<!-- Other stuff you need -->
</style>
</resources>
In your manifest set
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyTheme">
Now all of your ListView's will look like you define in style by default. You can of course change some of them if you want.
You can find a more complex, but very useful sample HERE
this question is already ask on stack overflow but didn't work for me.
I want to change my action bar color only like facebook app the top action is in blue color and rest of the thing has white background color.
I tried using the post in stack overflow but, it's change my full activity color to white instead of just only the action bar.
Here is my style.xml and
<style name="CustomActivityTheme" parent="#android:style/Theme.Holo">
<item name="android:actionBarTabStyle">#color/blue_base</item>
<!-- other activity and action bar styles here -->
</style>
manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActivityTheme">
Thanks.
You can't use a color directly, you have to use a drawable :
action_bar_bg.xml :
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/blue_base"/>
</shape>
Then this should work :
<item name="android:actionBarTabStyle">#drawable/action_bar_bg</item>
Now I realized where you did wrong. You can't pass color to actionBarTabStyle, you have to pass style. Instead you can define your style and pass it to it like this,
<style name="MyActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/ab_background</item>
</style>
This example from Android Developers page, if you take a look at there they explain very well.
There is another good article also on Android Developers Blog
I am trying to change the background of the app, but when I do the below (sdk 14) the items in the actionbar also change to match the new background color. The actionbar itself has the correct background, but the items in the actionbar do not. I was able to get the actionbarmenuitems to be correct, but the title and search view and home icon and back button all have the background set on the custom theme. What am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Holo.DarkerBack" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:background">#color/background</item>
<item name="android:actionBarStyle">#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse</item>
</style>
</resources>
Try replacing
<item name="android:background">#color/background</item>
with
<item name="android:windowBackground">#color/background</item>
I'm looking through the Holo.Light theme, and I can't seem to find the magic style to override to get rid of the title text that briefly shows up when my app first launches.
How can I do that?
Try:
getActionBar().setDisplayShowTitleEnabled(false);
For v.7:
getSupportActionBar().setDisplayShowTitleEnabled(false);
I think this is the right answer:
<style name="AppTheme" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="Widget.Styled.ActionBar" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:displayOptions">showHome|useLogo</item>
<item name="displayOptions">showHome|useLogo</item>
</style>
I'm very new to Android so correct me if I'm wrong, but I think if you decide to use navigation tabs on the Action Bar, they seemed to not be completely left aligned because the title text color is only transparent and hasn't gone away.
<style name="CustomActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">useLogo|showHome</item>
</style>
worked for me.
Got it. You have to override
android:actionBarStyle
and then in your custom style you have to override
android:titleTextStyle
Here's a sample.
In my themes.xml:
<style name="CustomActionBar" parent="android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/CustomActionBarStyle</item>
</style>
And in my styles.xml:
<style name="CustomActionBarStyle" parent="android:style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/NoTitleText</item>
<item name="android:subtitleTextStyle">#style/NoTitleText</item>
</style>
<style name="NoTitleText">
<item name="android:textSize">0sp</item>
<item name="android:textColor">#00000000</item>
</style>
I'm not sure why setting the textSize to zero didn't do the trick (it shrunk the text, but didn't make it go away), but setting the textColor to transparent works.
In your Manifest
<activity android:name=".ActivityHere"
android:label="">
Write this statement under
setContentView(R.layout.activity_main);
getSupportActionBar().setDisplayShowTitleEnabled(false);
if extending AppCompactActivity use getSupportActionbar() if extending Activity use getActionBar() else it may give
null pointer exception
using android:label="" in AndroidManifest.xml for activity also works but your app won't appear in Recently used apps
you have two choice:
first:
getActionBar().setDisplayShowTitleEnabled(false);
If usign getActionBar() produced null pointer exception, you should use getSupportActionBar()
Second
getSupportActionBar().setTitle("your title");
or
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
You can change the style applied to each activity, or if you only want to change the behavior for a specific activity, you can try this:
setDisplayOptions(int options, int mask) --- Set selected display
or
setDisplayOptions(int options) --- Set display options.
To display title on actionbar, set display options in onCreate()
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE, ActionBar.DISPLAY_SHOW_TITLE);
To hide title on actionbar.
getSupportActionBar().setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
Details here.
i use this code in App manifest
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:logo="#drawable/logo2"
android:label="#string/title_text"
android:theme="#style/Theme.Zinoostyle" >
my logo file is 200*800 pixel
and use this code in main activity.java
getActionBar().setDisplayShowTitleEnabled(false);
it will work Corectly
I tried this. This will help -
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar should be called after setSupportActionBar, thus setting the toolbar, otherwise, NullpointerException because there is no toolbar set.
Hope this helps
The only thing that really worked for me was to add:
<activity
android:name=".ActivityHere"
android:label=""
>
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().hide();
hope this will help
If you only want to do it for one activity and perhaps even dynamically, you can also use
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(actionBar.getDisplayOptions() ^ ActionBar.DISPLAY_SHOW_TITLE);
as a workaround just add this line incase you have custom action/toolbars
this.setTitle("");
in your Activity
Use the following:
requestWindowFeature(Window.FEATURE_NO_TITLE);
While all of these are acceptable, if your activity only contains a main activity, you can edit res\values\styles.xml like so:
<resources>
<!-- Base application 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>
</style>
</resources>
I've updated parent and added the .NoActionBar property to the Light theme from Android Studios Create Blank Application Wizard.
Simply extends your java file from AppCompatActivity and do this:
ActionBar actionBar = getSupportActionBar(); // support.v7
actionBar.setTitle(" ");
In your manifest.xml page you can give address to your activity label. the address is somewhere in your values/strings.xml . then you can change the value of the tag in xml file to null.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="title_main_activity"></string>
</resources>
I am new to Android so maybe I am wrong...but to solve this problem cant we just go to the manifest and remove the activity label
<activity
android:name=".Bcft"
android:screenOrientation="portrait"
**android:label="" >**
Worked for me....
I remove the default appbar and run a custom toolbar instead using Theme.AppCompat.Light.NoActionBar then add a textview or something that extend to full toolbar width using attribute layout_width=match_parent and it pushes the title out of the toolbar. If you want to do this, you must study how to make a toolbar.
ActionBar actionBar = getActionBar();
actionBar.setTitle("");
I am using a titlebar with a background image in my android app.
values/custom_styles.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="TitlebarBackgroundStyle">
<item name="android:background">#drawable/titlebar</item>
</style>
<style name="Theme.MyCustomTheme" parent="android:Theme">
<item name="android:windowTitleBackgroundStyle">#style/TitlebarBackgroundStyle</item>
<item name="android:windowTitleSize">45dp</item>
</style>
</resources>
layout/titlebar.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:gravity="center_vertical">
<ImageView
android:id="#+id/header"
android:src="#drawable/titlebar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Manifest:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:theme="#style/Theme.MyCustomTheme">
This works pretty well so far.
The only thing I'd like to do now is to hide the text on the titlebar ...
I tried:
<item name="android:textSize">0dp</item>
but with no luck. Is there any way to set the transparency or some other property that would allow me to see the background image but not the text?
thanks for your thoughts
Ron
If you are working on API level 11 or above than do this in your activity
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
Or you can do this by applying custom style to your activity like
<style name="CustomWindowTitle" parent="android:TextAppearance.WindowTitle">
<item name="android:visibility">gone</item>
</style>
<style name="MainTheme" parent="#android:Theme">
<item name="android:windowTitleStyle">
#style/CustomWindowTitleText</item>
</style>
And then add it to your activity like
<activity
......
android:theme="#style/MainTheme"/>
You can do it in Java, not resource xml, since the TextView on the title bar is determined programmatically by some lines in the Android Java source code.
You can hide the title bar's TextView in this way :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
root = (LinearLayout) decorView.getChildAt(0);
FrameLayout titleContainer = (FrameLayout) root.getChildAt(0);
TextView title = (TextView) titleContainer.getChildAt(0);
title.setVisibility(View.GONE);
}
I'm not sure, but you can also try to declare your activities without label in manifest.
<activity android:name="...">
Add this to your manifest
<application android:label="bla bla"
android:icon="#drawable/bla bla"
---> android:theme="#android:style/Theme.NoTitleBar">
Try to set an empty custom titlebar with an empty layout.
Boolean customTitle = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.listviewoffers);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebarlayout);
Fortunately the way is too simple (I guess you do have a custom layout for your title)
If you don't know to do how please take a look: How to Create Custom Window Title in Android
Hiding the default title text is one line of code. Just write setTitle(""); inside onCreate().
That's it! Hope this helps!
Set your theme to a custom theme for the activity. The theme would look like this:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Black.OptionalActionBar" parent="#android:style/Theme.Black.NoTitleBar">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="android:actionBarStyle">#style/MyActionBarStyle</item>
</style>
<style name="MyActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showHome</item>
</style>
<style name="OptionalVisibility">
<item name="android:visibility">invisible</item>
<item name="android:height">1dp</item>
</style>
</resources>
The ActionBarStyle overrides the behavior of the action bar. Notice I set the style to the holo actionbar and then change the displayOptions to showHome. This will only show the home icon. You can also set it to showTitle which will only show the text. Or both showHome|showTitle. If you leave it blank, <item name="android:displayOptions"></item> then the text and icon will go away all together.
NOTE: I know this will work for 3.0 (api 11) and above...I am not certain if it will work for lower API levels.
I know this is years old...but posting for others who encounter this problem.
android:theme="#android:style/Theme.NoTitleBar">
adding this in your manifest file works..
android:label=""
add this to manifest