I'm having an issue with Togglebuttons when not specifying a theme.
If I use any theme they look fine but if I remove the android:theme="#style/AppTheme" tag from AndroidManifest.xml Togglebuttons add an unwanted icon.
Sample image here:
I made a sample project with just a togglebutton with following xml layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</RelativeLayout>
and this is how it looks.
I think I need to define a new theme inheriting from device default theme to override the togglebutton icon but I've had no success so far.
Related
For some reasons when I launch the app in the splash activity and in the row activity, see images, there is a header bar with the name of the app "Baby Read".
I don't want the header there, how do I get rid of it?
Splash Activity
Row Activity
[![enter image description here][2]][2]
This is the splash layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/babyreadappsplash"
>
</LinearLayout>
And this is the row layout:
<?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"
>
<ImageView
android:id="#+id/icon"
android:layout_width="90px"
android:layout_height="90px"
android:layout_marginLeft="10px"
android:layout_marginRight="10px"
android:layout_marginBottom="10px"
android:layout_marginTop="10px"
android:src="#drawable/ic_launcher" >
</ImageView>
<TextView
android:id="#+id/label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#+id/label"
>
</TextView>
This is res/values/styles after adding the code suggested
[![enter image description here][3]][3]
And this is the manifest after adding the code suggested
Create a style for your splash Activity like this
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
</style>
after that set this style for your splash Activity in Manifest
<activity
android:name="activity name"
android:theme="#style/AppTheme.NoActionBar"
/>
Update
make your style like this
<style name="splashStyle" parent="Theme.AppCompat.Light.NoActionBar">
//add other attributes
</style>
if not work for you change the parent of your AppTheme to Theme.AppCompat.Light.ActionBar
You can use this in onCreate:
getSupportActionBar().hide();
No need to create anew theme (At least for this purpose)
Modify you app theme (Picture one)change parent="android:Theme.Holo.Light.DarkActionBar" for parent="android:Theme.Holo.NoActionBar"
On you manifest, in the application section (picture 2)add
android:theme="#style/AppTheme"
If by any change you are supporting APIs below 13 you can add
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
to your app theme rather than changing the parent.
As a side note I would advise moving from Holo themes to Appcompat or even Material, but that´s out of the scope of this question
I have an app with a simple recyclerview.
The layout is declared as follow
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/some_id" />
</RelativeLayout>
I notice that on different devices, the recyclerView actually had a different background. In newer devices, the background is just white. On older devices, the background is light gray.
In android studio, the background color is blank in the design view.
So my question is, where does this gray color come from? How can I change it universally to white?
I can obviously just add background:white to this particular view. But is there a way to overwrite the system default?
Android default background color
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground">
</RelativeLayout
use
android:background="?android:colorBackground"
What you are seeing is actually the background of the activity, not the recyclerview, which is transparent by default. The color did change a view time per Android version.
You can override this in your app theme.
First define the color in values/colors.xml
<resources>
<color name="background">#FF0000 </color>
</resources>
Create a themes.xml file in res/values that references that color:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Light">
<item name="android:windowBackground">#color/background</item>
</style>
</resources>
and then in your AndroidManifest.xml specify this as
the theme for your activities to use.
<activity
android:name=".MyActivity"
android:theme="#style/MyTheme" />
see https://stackoverflow.com/a/10157077/4623782
it's because of theme. specify your theme in res/values/style.xml. or set manually in view definition.
<android.support.v7.widget.RecyclerView
android:id="#+id/contentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/some_id"
android:background="#android:color/white"
/>
it will give you white background on all device
The color of the background which is set by default in any android studio project is #fafafa
first please check this image:
It shows an Spinner beautiful and nice, my Spinner looks like that:
Here is all my source code.
Activity xml:
<?xml version="1.0" encoding="utf-8"?>
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="amaz1ngc0de.com.br.spinnertest.MainActivity">
<Spinner
android:id="#+id/sp_paymentType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
</Spinner>
</RelativeLayout>
My question is: How can I achieve the same layout showed at tutorial?
PS: I have checked this topic: Correct usage of a Spinner, following material design guidelines it says something about themes, but I can't make it work, and the tutorial I'm following is that one: Spinners
Your tutorial is quite dated, unfortunately. The first screenshot you're showing is in the Holo style. What you've created uses the newer and better Material Design. Good job, you bested the tutorial!
However, if you really wanted to achieve the same effect, you can go backwards to the old look, by setting your activity to use the Holo theme. You can do that in your AndroidManifest.xml:
<activity
android:name="..."
android:theme="#android:style/Theme.Holo.Light" />
Or if you are using your custom theme then set is a parent:
<style name="AppTheme" parent="android:Theme.Holo.Light">
If you want to change the look of just the Spinner, not the whole screen, you can use android:theme on your Spinner:
<Spinner
android:id="#+id/sp_paymentType"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:theme="#android:style/Theme.Holo.Light">
I'm trying to style my EditTexts (and AutoCompleteTextViews) a certain way so that the line is a color that I specify. Normally, this work's just fine by following this answer: How to change the color of the line in ICS styled EditText.
However, it appears as though the style I define for my EditTexts is not observed when the EditText is part of an ActionView in the ActionBar menu.
I.e., I have an action view item in my menu.xml file:
<item
android:title="Search"
android:icon="#drawable/search_icon"
android:showAsAction="always|collapseActionView"
android:actionLayout="#layout/search_layout"
/>
I specify the layout to be used when this is expanded with the actionLayout property, and then I have a search_layout.xml file that looks 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="match_parent"
android:orientation="horizontal" >
<EditText
android:inputType="text"
android:hint="Enter Search Term"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
This EditText doesn't take on the styling that I've defined in my styles.xml (and the same thing happens if it's an AutoCompleteTextView instead). How can I customize the style of an EditText/AutoCompleteTextView when it's a part of an ActionView?
As William said in the first comment on my question, the solution is to explicitly set the style on the EditText by adding style="#style/YourStyle" to the EditText in search_layout.xml.
My applications minSdkVersion is 15. So the buttons in the application will get a light blue color when the user touches it. Later i added a custom title for the application. After that my application components color is changed to orange when the user touches it. I found that it is the problem with the custom title. How to solve it. I need the features of sdk version 15. Please see how i added the custom title bar.
My Manifest.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/CustomTheme">
My style used for the custome title bar (custom_style.xml)
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">30dip</item>
</style>
</resources>
Activity code where it changes to the Custome title bar
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
My title bar layout(window_title.xml)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="30dip"
android:background="#FF0000" >
<ImageView
android:id="#+id/header"
android:src="#drawable/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"/>
<Switch
android:id="#+id/laodAutomatically"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MirrorLink auto-connect"
style="#android:style/Theme.Holo"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
Your theme should probably inherit from a theme, which is a theme for the SDK 15. There's a nice tutorial that will get you started with supporting various SDK versions with themes and styles. Hope this helps.
http://developer.android.com/guide/topics/ui/themes.html
Your theme should selectively inherit either Theme, or android:Theme.Light, depending on the platform version. Look towards the end of this page.