I get following error in the Preview window of Android Studio:
Rendering Problems Missing styles. Is the correct theme chosen for
this layout? Use the Theme combo box above the layout to choose a
different layout, or fix the theme style references. Failed to find
'?attr/actionBarPopupTheme' in current theme. (4 similar errors not
shown)
I have created a custom style/theme. This is the regarding styles.xml:
<resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomActionBarTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBar</item>
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTheme">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background" tools:ignore="NewApi">#color/white</item>
<item name="titleTextStyle">#style/MyActionBar.ActionBar.TitleTextStyle</item>
<item name="background">#color/bg_common</item>
</style>
<style name="MyActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="actionMenuTextColor">#color/title</item>
<item name="colorControlNormal">#color/title</item>
</style>
<style name="MyActionBar.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/title</item>
</style>
</resources>
My layout file header looks like this:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
style="#style/CustomActionBarTheme"
android:id="#+id/drawer_layout"
android:background="#color/bg_common_2"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
...
And in my manifest file I have added in the application tag:
android:theme="#style/CustomActionBarTheme"
Why do I get the error? I also choosed CustomActionBarTheme in my Preview windows as Theme. Am I missing something? Thanks for any advice in advance!
Android Studio uses the latest SDK installed to preview layout files. This can lead to preview errors due to missing styles - switching to an older API level (e.g. from 23 to 22) can fix this.
Another way is to change layout theme (near SDK preview version button)
Works fine
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"/>
I'm using background image in my toolbar, and from some reason the toolbar is working only with mipmap and not with drawable.
In my app_bar_main.xml file:
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#mipmap/bar"
app:popupTheme="#style/AppTheme.PopupOverlay" />
As you can see I've used mipmap instead of drawable, though when I'm using drawable the application crashes and the following error is given:
Binary XML file line #11: Binary XML file line #16: Error inflating
class android.support.v7.widget.Toolbar
Must mention this mipmap using is just making my app very slow, and it skipping frames, so I would like to change it to drawable.
How can I change the toolbar background resource of the image from mipmap to drawable?
EDIT:
Style.xml
<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>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="LightDialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="android:textColor">#android:color/primary_text_light</item>
<item name="background">#drawable/bar</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
Seems your xml file is perfect.
What I suggest ,Just resize that image or prepare background image with different different size, which you want to set in to your toolbar and put it in to different drawables / mipmap folders.
android:background="#mipmap/bar"
as we know icon size should be ,
drawable-ldpi (120 dpi, Low density screen) - 36px x 36px
drawable-mdpi (160 dpi, Medium density screen) - 48px x 48px
drawable-hdpi (240 dpi, High density screen) - 72px x 72px
drawable-xhdpi (320 dpi, Extra-high density screen) - 96px x 96px
run your app again and do let me know .
toolbar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/MyToolbarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical">
Themes/Style
<style name="MyToolbarStyle">
<item name="android:maxHeight">#dimen/abc_action_bar_default_height_material</item>
<item name="android:background">#color/primary</item>
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="titleTextAppearance">#style/Theme.Toolbar.Title</item>
<!-- No need for colorPrimary, colorPrimaryDark, colorAccent here
this should go to the AppTheme -->
Try this methos,it works..
Please add this code in your app level build.gradle file
android {
defaultConfig {
.....
vectorDrawables.useSupportLibrary = true
}
}
toolbar_default.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
style="#style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="#dimen/abc_action_bar_default_height_material"/>
ToolBarStyle
<style name="ToolBarStyle" parent="">
<item name="popupTheme">#style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">#style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
Other
Please remove below line from you toolbar and try to check it work or not.I am not sure but you just check it.
app:popupTheme="#style/AppTheme.PopupOverlay"
I hope this will help you
My problem is that I can't seem to override androids default tab padding and it's making my tabs horizontally scrollable (which I don't want). I've searched around stack overflow and other sites online but i can't find a solution for my problem. I am using appcompat-v7 and I'm targeting api 21 with my minimum sdk set to api 14.
Here is my themes.xml
<style name="TSTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="colorPrimary">#color/primary_blue_500</item>
<item name="colorPrimaryDark">#color/dark_blue</item>
<item name="colorAccent">#color/primary_blue_500</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/primary_blue_500</item>
</style>
<style name="ActionBarTabStyle"
parent="#style/Widget.AppCompat.Light.ActionBar.TabView.Inverse">
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:paddingTop">0dp</item>
</style>
I have tried adding android: prefix but it still doesn't do anything. I have also defined my custom theme in my manifest
Any and all help is much appreciated
For this you will have to create your own style and then you can set that style to actionbar manually. This is the only way to make it done.
<item name="toolbarStyle">#style/Widget.Toolbar</item>
<style name="Widget.Toolbar" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
</style>
I was making an android app in eclipse, using some Holo elements in the UI. It worked fine. Then I deleted the eclipse and sdk folder, and redownloaded it. Didn't touch the app at all in the interim. Now all the holo effects are gone, as you can see in the pictures below. How can I fix this? Thanks.
Before:
After:
Here is my styles.xml:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Black">
<item name="android:editTextStyle">#style/edittext_holo</item>
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<style name="edittext_holo" parent="#android:style/Widget.EditText">
<item name="android:focusable">true</item>
<item name="android:focusableInTouchMode">true</item>
<item name="android:clickable">true</item>
<item name="android:background">#drawable/edit_text_holo_dark</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:gravity">center_vertical</item>
<item name="android:textColorHint">#FFFFFF</item>
<item name="android:textColorHighlight">#FF0000</item>
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
</style>
</resources>
The problem is that your AppBaseTheme style inherits from android:Theme.Black.
This is the pre-Holo default theme.
Your theme should inherit from a Holo theme (such as android:Theme.Holo). Based on your screenshot, you want Theme.Holo.Light.DarkActionBar, so your styles.xml should look like this:
<style name="AppBaseTheme" parent="android:Theme.Holo">
If you are supporting any SDK version below 14, this should go in the values-14/styles.xml file, as Holo does not exist on pre-14 devices.
For more information, see the Styling the Action Bar and the Styles and Themes documentation.
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