I added Theme.Appcompat to my application and and now the search icon and the blue line are gone from my search bar. Does anybody know how to get the Holo theme to work with the Theme.Appcompat
follow material design guidelines when using appcompact library
use a toolbar and add your views to it, style it as per your needs, i just made gradient for timebeing.
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#drawable/mygradient"
app:popupTheme="#style/AppTheme.PopupOverlay"
>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="match_parent"
android:gravity="center"
android:weightSum="1">
<EditText
android:layout_width="30dp"
android:layout_height="wrap_content"
android:hint="Search for videos"
android:drawableLeft="#drawable/icon"
android:layout_weight="0.86" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
change the accent color to your holo blue
<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>
Related
is it possible to customize the background (and title) of my action bar in a specific activity? What I have done and it's not working:
<style name="AppTheme.BenchTheme"> <!-- style of my activity -->
<item name="android:windowBackground">#android:color/holo_blue_light</item>
<item name="android:actionBarStyle">#style/BenchActionBar</item>
</style>
and
<style name="BenchActionBar">
<item name="android:background">#color/colorBench</item>
</style>
I want to do it in my style.xml. Is it possible? I know I can do it via code (using something like getSupportActionBar().setBackgroundDrawable(myColor);)...
Thanks
First make your Theme extend from Theme.AppCompat.Light.NoActionBar:
<style name="AppTheme.BenchTheme" parent="Theme.AppCompat.Light.NoActionBar">
Then in your layout you can already add the toolbar as you want for example:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/kelly_green"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
style="#style/MyToolbarElevation"
>
<android.support.v7.widget.AppCompatTextView
android:id="#+id/txt_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="#dimen/_2sdp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="#dimen/_13sdp"
/>
</android.support.v7.widget.Toolbar>
I am trying to change color of home arrow indicator in custom toolbar.
There is list of examples that I found but nothing worked for me.
Here is my layout
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/title_bar_toolbar_id"
app:theme="#style/ToolbarColoredBackArrow"
app:popupTheme="#style/AppTheme"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:colorControlNormal="#color/hamburger_color"
android:background="#color/custom_theme_color" >
<LinearLayout
android:id="#+id/base_title_bar_toolbar_id_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/activity_calendar_toolbar_change_view_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/select_semester_view"
android:layout_gravity="center_vertical"
android:padding="10dp" />
<TextView
android:gravity="center"
android:layout_gravity="center"
android:id="#+id/base_title_bar_toolbar_header"
android:layout_weight="0.1"
style="#style/CustomToolBarTitleStyleBase"
android:text="#string/calendar" />
<ImageView
android:padding="13dp"
android:id="#+id/activity_calendar_toolbar_save_date_to_calendar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/save_date_to_calendar"
android:layout_gravity="center_vertical|start" />
<ImageView
android:id="#+id/activity_calendar_toolbar_select_semester_to_show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/select_semester_to_show"
android:layout_gravity="center_vertical|start"
android:padding="13dp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
The styles are:
<style name="ToolbarColoredBackArrow" parent="AppTheme">
<item name="android:textColorSecondary">#color/hamburger_color</item>
<item name="android:textColorPrimary">#color/hamburger_color</item>
<item name="colorControlNormal">#color/hamburger_color</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/custom_theme_color</item>
<item name="android:titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
<!-- Support library com`enter code here`patibility -->
<item name="background">#color/custom_theme_color</item>
<item name="titleTextStyle">#style/MyActionBar.TitleTextStyle</item>
</style>
I tried all possibilities that I found in examples,
but nothing worked for me.
Haha, this is one of the most frustrating styling issues in Android right now...
Try creating a style like this
<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textColorSecondary">#000000</item>
</style>
and using it in your Activity (you will probably want to merge it with your current style, as it is just the parent and this one param that matters) and of course replace the #000000 with some other color.
First of all you don't need a separate ImageView for your arrow navigation button. Just use the one from support design resources which will resize automatically according to the screen size.
Drawable upArrow = getResources().getDrawable(android.support.v7.appcompat.R.drawable.abc_ic_ab_back_mtrl_am_alpha);
upArrow.setColorFilter(Color.parseColor("#ffffff"), PorterDuff.Mode.SRC_ATOP);
toolbar.setNavigationIcon(upArrow);
I am creating my own action bar with menu items and therefore using Theme.AppCompat.Light.NoActionBar.
I want to have the action bar purple and the title color white, but at the moment it is black.
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
my action bar xml is:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:id="#+id/app_bar"
>
As explained in this Google+ pro-tip, you can use a ThemeOverlay to customize only certain things. This is useful for when you need to make text light on a dark background, which can be achieved by adding android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" to your Toolbar:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:id="#+id/app_bar"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
>
This technique was further discussed in the Theming with AppCompat blog+video.
current layout
I have a problem related to xml layout, and I don't know how to add primary and primary dark color. Can anybody help me?
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView android:id="#+id/in"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
android:layout_weight="1"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText android:id="#+id/edit_text_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="bottom"/>
<Button android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/send"/>
</LinearLayout>
</LinearLayout>
How it should look like
You should modify, or create if it didn't exists already the file styles.xml, in the values folder, like that :
<style name="MyMaterialTheme.Base" >
<!-- Primary Color -->
<item name="colorPrimary">#color/colorPrimary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/colorAccent</item>
</style>
It gets it's values from colors.xml file.
Do you mean you need to change the color of action bar located at top most position right? Then do this:
so, ActionBar will not work for your target environment which is at API level 10 (Android 2.3.3).
Just in case, if you target for minimum API level 11, you can change ActionBar's background color by defining custom style, as:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
And, set "MyTheme" as theme for application/activity.
I'm currently using the usually amazing appcompat-v7 library in my application and I'm trying to tint my CheckBoxes without changing the Icon-Colors in the Toolbar (like the back arrow or those three dots).
Following how it looks currently - as you can see not only the CheckBox is tinted pink, the back-arrow / three-dots are also tinted pink.
My code:
Layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
android:elevation="4dp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="My CheckBox" />
</LinearLayout>
Application-Theme
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#FFC107</item>
<item name="colorPrimaryDark">#FFA000</item>
<item name="android:textColorPrimary">#FFF</item>
<item name="android:textColorSecondary">#FFF</item>
<item name="colorControlNormal">#E91E63</item>
</style>
Question
What do I need to change so that the Checkbox gets pink and the Toolbar-stuff keeps being white?
Side-Note:
I guess the main problem is that I simply can't find a page where every single appcompat attribute is described. It's basically just all-out trial and error since the names of those attributes are no clear indication.
You're basically facing the same issue as described in this or this question.
So the only thing you need to do is to create a Style for your Toolbar which uses an other theme as the Activity.
Toolbar style / theme example
<style name="MyToolbarStyle">
<!-- potential other attributes -->
<item name="theme">#style/MyToolbarTheme</item>
</style>
<style name="MyToolbarTheme">
<!-- Used to tint the back arrow, menu and spinner arrow -->
<item name="colorControlNormal">#FFF</item>
</style>
Add this Style to your Toolbar and your issue should be fixed (it is important not to use the theme directly):
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
style="#style/MyToolbarStyle"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:background="?colorPrimary"
android:elevation="4dp" />