assign a theme to the application in android studio

1

good, I have an application that has a theme created by default in android. I was compiling it with an api 23 but the cell phones where the application will run have an api 19. I downloaded the api 19, but when selecting the api 19 in the upper part of the emulator the theme is no longer displayed, nor the bar. in the manifest I put

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >

but the same is not shown, it only comes out with the api23. I show screens 19 and 23 respectively.

This is the style I use:

<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>
    
asked by ICRUZ 31.05.2016 в 22:06
source

2 answers

2

Thing you should have in mind about topics on Android

res / values / style.xml = > style where it will be applied in all versions

<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>

res / values-21 / style.xml = > style where only api 21 version will be applied

the Activity must exclude AppCompatActivity

public class MainActivity extends AppCompatActivity

Apart from that, not being the version of Android Studio you have, the most recent ones, with creating a new project, it will arm you to work well, add the compatibility library to use Material Design.

    
answered by 01.06.2016 в 11:44
1

Well, in your file build.gradle you should have added something like this

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:recyclerview-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    .....
}

So now you can use the components (widgets) of the library, for example for AppBarLayout you can do something like this

<!-- Resto de tu Layout -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="6">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar"></include>
    </android.support.design.widget.AppBarLayout>

Note the prefix android.support.design.widget for AppBarLayout , the example uses a include therefore you must have a xml called tool_bar.xml with the following content (notice the prefix)

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@color/in_black"
    android:theme="@style/ThemeOverlay.AppCompat.Dark"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

</android.support.v7.widget.Toolbar>

In your style.xml (for example) you could have something like this

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">tu primary color</item>
    <item name="colorPrimaryDark">tu primary dark color</item>
    <item name="colorAccent">tu accent color</item>
    <item name="android:textColorHint">etc ...</item>"
</style>

The detail is in using those components that are only available for API's > = 21 through the compatibility library.

As you mention, API 19 is Android 4 (and for your capture) but components with look and feel Material are only available natively for API > = 21 (Android 5 or higher)

If you have any questions I recommend you read this post that although it is in English It is very intuitive and you can clear those doubts.

    
answered by 31.05.2016 в 23:50