Bilal Ahmed Bilal Ahmed - 1 year ago 56
Android Question

By running the App on versions below 22 Changes some views?

I am developing an app with minSdkVersion 11, targetSdkVersion 23 and compile/build tool version 23. On android versions, 5 and 6 my app works fine, but installing the app on versions below 22 modifies some layouts, like buttons and text fields disappear or color changes, help me with this.

Manifest File

<manifest xmlns:android=""


Styles file


<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:windowNoTitle">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

<style name="AppTheme.AppBarOverlay"
parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay"
parent="ThemeOverlay.AppCompat.Light" />


Build Gradle

apply plugin: ''

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
applicationId "com.khan.bilal.salamrides2"
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile ''
compile ''
compile ''

Screen Shot of android version 22(Works fine)
Working fine

Screen Shot of android version below 22(problem occurs)
enter image description here

Answer Source

When you use an element that was introduced in API 21, and you try to show it on a phone with API 11, there surely will be a problem. For the older versions, you have to differentiate between the elements that you are showing - if some element is not meant to be used in API lower than 21, then you have to provide if-else check and if the API is lower than 21, then use some simple element that you are sure was supported even in API 11.

For example, if you want to use TextInputLayout, you surely can, as the library supports API 22+, but for the lower versions you should probably input text by adding classic EditText. You add both of them to your XML, hide them, and then based on user's API you show one or other.

Also, read this document.

Especially this should help you get an idea what and how to do it:

private void setUpActionBar() {
// Make sure we're running on Honeycomb or higher to use ActionBar APIs
    ActionBar actionBar = getActionBar();

Good luck :)