I am new to Android development. I have followed the Android Overlay training at:
http://developer.android.com/training/basics/actionbar/overlaying.html
and spent the last few days trying to get this to work. I am using the AppCompat library and my min SDK is 7 and my max sdk is 18.
My application defines a custom style and looks like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name="com.example.rtrt.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
My layout looks like this:
<RelativeLayout 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"
tools:context=".MainActivity" >
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/clickme"
android:onClick="sendMessage" />
</RelativeLayout>
My theme.xml looks like this:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style> <!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar">
<item name="android:background">#android:color/transparent</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
The application compiles and runs... however, the Button appears below (not under) the ActionBar. When I hide the ActionBar the Button moves to the top of the screen. When the ActionBar is made visible, the Button is repositioned down the screen.
Why is my ActionBar not floating (overlaying)?
Would appreciate any help here.
It is because you are targeting below SDK 11.
change your theme to AppCompat and not AppCompat.Light:
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.AppCompat">
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
</style>
Related
I want to port my app to android support library v7 revision 23.1.
For this purpose I have extended my theme from Theme.AppCompat.NoActionBar as instructed in multitude of guides.
<style name="MyTheme" parent=" Theme.AppCompat.NoActionBar ">
The problem is that the activity shows old android title bar with the name of my application and I cannot remove this title bar. Regarding this the support library is a big step backwards in comparison to holoeverywhere. Not to mention load of other bugs.
I have tried to remove title bar using following adition to my theme:
<style name="MyTheme" parent=" Theme.AppCompat.NoActionBar ">
...
<item name="windowNoTitle">true</item>
<item name="android:windowNoTitle">true</item>
...
</style>
But the title bar persists.
The device runs with android 2.3.5.
How to remove title bar?
You must set
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
also using toolbar
<android.support.v7.widget.Toolbar
android:id="#+id/activity_main_page_toolbar"
android:layout_height="#dimen/actionbar_height"
android:layout_width="match_parent"
android:background="#drawable/actionbar_background"
android:textColorPrimary="#android:color/white"
app:theme="#style/Theme.CustomAppCompat">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_logo"
android:background="#drawable/menu_item_drawable"
android:padding="5dp"
android:clickable="true"
android:id="#+id/toolbar_icon" />
<include layout="#layout/notif_layout" />
</android.support.v7.widget.Toolbar>
Try to create such a style.xml.Its for full screen app.So just delete fullscreen for NoTitleBar.And windowFullScreen to false.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<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>
</resources>
And such a Mansifest.xml.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="by.test.roma.usermetrics" >
<application
android:name=".ParseApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
I want so set backgroung image to actionbar of main activity and all activities too and also want to chnage text color of text of action bar
i tried this code but it giving me error
plz help me
style.xml
<resources>
<!-- Base application theme. -->
<style name="AppThe" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="ActionBar" parent="#android:style/Widget.Holo.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
</style>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
</resources>`
manifest code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.navigationd"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="OLXA"
android:theme="#style/AppThe" >
<activity
android:name="com.example.hp.navigationd.MainActivity"
android:label="OLXA" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.hp.navigationd.post_ad"
android:label="#string/Ad_Details"
android:parentActivityName="com.example.hp.navigationd.MainActivity" />
<activity android:name="com.example.hp.navigationd.My_account" />
<activity android:name="com.example.hp.navigationd.My_fav" />
<activity android:name="com.example.hp.navigationd.My_ads" />
<activity android:name="com.example.hp.navigationd.My_chats" />
<activity android:name="com.example.hp.navigationd.Rules" />
<activity android:name="com.example.hp.navigationd.Help" />
<activity android:name="com.example.hp.navigationd.About_us" />
</application>
</manifest>
Try this,
Insted of using,
<style name="AppThe" parent="Theme.AppCompat.Light.DarkActionBar">
use this,
<style name="AppThe" parent="#android:style/Theme.Holo.Light.DarkActionBar">
Check out the below style.
<style name="AppThe" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<item name="background">#drawable/actionbar_background</item>
</style>
Here you need to use both you both android:actionBarStyle and actionBarStyle as well as android:background and background items. The former is for newer versions of android that support ActionBar natively. The latter is for older android versions.
About the error:
You can not use "#android:style/Theme.Holo.Light" with AppCompatActivity
OK, I know this is a trivial issue but for some reason it isn't working for me. I have done a lot of things suggested in other answers but in vain. My drawable folder has white color icons. I even tried to change it from styles.xml but that doesn't work either. I am testing it on my Lollipop device. Any help will be appreciated. Thanks in advance.
This is a portion of my manifest file.
<application
android:allowBackup="true"
android:icon="#drawable/ic_drawer"
android:label="#string/app_name" >
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"
tools:replace="android:value" />
<activity
android:name=".Activity_Splash"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity_test"
android:launchMode="singleInstance"
android:theme="#style/AppTheme.Base"
android:windowSoftInputMode="stateHidden" />
And finally this is my style.xml. Similar is for v-21.
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:actionMenuTextColor">#fff</item>
<item name="colorPrimary">#color/ColorPrimary</item>
<item name="colorPrimaryDark">#color/ColorPrimaryDark</item>
<item name="drawerArrowStyle">#style/MyDrawerArrowToggle</item>
<item name="windowActionBar">false</item>
<item name="colorAccent">#fff</item>
<item name="android:windowSharedElementEnterTransition">#android:transition/move</item>
<item name="android:windowSharedElementExitTransition">#android:transition/move</item>
</style>
You should use ThemeOverlay.AppCompat.Dark.ActionBar as your toolbar style. It sets colorControlNormal to android:textColorPrimary, which is white for dark themes. And it doesn't change other attrs from main style.
<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto" >
...
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
</android.support.v7.widget.Toolbar>
Also remove drawerArrowStyle from your main style, it's not needed.
If you are using the Design support library, you can modify the icon colours using the app:itemIconTint property:
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme"
app:headerLayout="#layout/nav_header_main"
app:itemIconTint="#f00"
app:itemTextColor="#0f0"
app:menu="#menu/nav_drawer" />
As a bonus, above also shows how to change the colour of the text with app:itemTextColor.
I updated my SDK API 20 to API 22 in Eclipse.
After Updating My Sdk i Imported My Project from Other Workspace
Problem:
Actionbar App icon Not Showing in My Application.
I Already set theme Color in Themes.xml thats not Showing. it Changed as Default Black Colour.
Its Changed full structure of my App. Before Updating it works fine.
Please anyone Help me to Solve this.
manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/logo"
android:label="#string/app_name"
android:largeHeap="true"
android:theme="#style/CustomActionBarTheme" >
<activity
android:name="com.example.Start"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">#style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">#style/Divider</item>
</style>
<!-- for Tab divider -->
<style name="Divider" parent="#android:style/Widget.Holo.ActionBar.TabBar">
<item name="android:divider">#android:color/transparent</item> //or use your transparent drawable image
<item name="android:showDividers">middle</item>
<item name="android:dividerPadding">0dp</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/easy</item>
<!-- Support library compatibility -->
<item name="background">#color/easy</item>
</style>
<style name="MyActionBarTabs" parent="#style/Widget.AppCompat.ActionBar.TabView">
<item name="android:background">#drawable/actionbar_tab_indicator</item>
</style>
<style name="MyTheme.ActionBar.TabText" parent="android:style/Widget.Holo.ActionBar.TabText">
<!-- This is a Black text color when selected and a WHITE color otherwise -->
<item name="android:textColor">#color/selector_tab_text</item>
</style>
</resources>
I had the same problem.
To show icon use:
getSupportActionBar().setIcon(R.drawable.ic_your_icon);
in your activity onCreate()
And for color add:
<item name="colorPrimary">#color/your_color</item>
to "CustomActionBarTheme" (not to "MyActionBar"!)
And your theme should look like:
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabStyle">#style/MyActionBarTabs</item>
<item name="colorPrimary">#color/your_color</item><!--put your color here-->
<!-- Support library compatibility -->
<item name="android:actionBarTabTextStyle">#style/MyTheme.ActionBar.TabText</item>
<item name="android:actionBarTabBarStyle">#style/Divider</item>
</style>
And the other stuff in your theme.xml stays unchanged
I am following the android training , in styling the Action bar.
I am facing error because of android:theme=#style/MyActionBar.
I want to know how to style the action bar.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyActionBar" >
IllegalStateException: You need to use a Theme.AppCompat theme with
this activity
I thought the error from :
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
so I modify it to
<style name="CustomActionBarTheme"
parent="#android:style/Theme.AppCompat.Light ">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
I had the following error :
error: Error retrieving parent for item: No resource found that
matches the given name '#android:style/Theme.AppCompat.Light '.
I created a new file as the training explained
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">#aaaaaa</item>
</style>
</resources>
And here is the manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/MyActionBar" >
<activity
android:name="com.example.helloworld.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.helloworld.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.Helloworld.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.Helloworld.MyActivity" />
</activity>
</application>
</manifest>
edit your style as follows:
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#drawable/actionbar_background</item>
</style>
for support library you have to use
name="background">#drawable/actionbar_background</item>
instead of
name="android:background">#drawable/actionbar_background</item>
and then use this theme in your manifest...
before use don't forget to add support:appcompact dependencies in build.gradle if you are using Android Studio...
thanks...
appcompat v7 libary has two kinds of files. One is jar, the other is reses like string.xml styles.xml. You question implies that you didn't import reses of appcompat library. So, import the project of .../Android-SDK/sdk/extras/android/support/v7/appcompat into your Eclipse, and then add it as a libary project of your main project.
I think you have not added a reference of appcompat lib in your project. Add the reference of it to your project and check
https://developer.android.com/tools/support-library/setup.html