TextInputLayout Crashing in Android Lollipop and Above - android

I am using TextInputLayout in one of my app layouts. My app is crashing on user's devices with Lollipop(5.1) version and above.
Below is the error
android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #34: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by android.view.InflateException: Binary XML file line #2: Error inflating class android.support.design.widget.TextInputLayout arrow_drop_down
Caused by java.lang.reflect.InvocationTargetException: arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/design_password_eye.xml from drawable resource ID #0x7f0200b1 arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password.xml from drawable resource ID #0x7f02005c arrow_drop_down
Caused by android.content.res.Resources$NotFoundException: File res/drawable-v21/avd_show_password_1.xml from drawable resource ID #0x7f0201bd arrow_drop_down
Caused by org.xmlpull.v1.XmlPullParserException: Binary XML file line #1: invalid drawable tag x
I have tried all solutions at StackOverflow but they are not working. This include updating my libraries, using android:theme="#style/Theme.AppCompat" but my the app is still crashing.
TextInputLayout
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="#style/Theme.AppCompat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittext_bg"
android:id="#+id/passwordInput"
app:hintTextAppearance="#style/UI.Text.HintText"
app:errorTextAppearance="#style/UI.Text.ErrorText"
android:textColorHint="#color/inputLabelColor"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#000000">
<EditText
android:textSize="18sp"
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
android:textColorHint="#color/inputLabelColor"
android:textColor="#android:color/black"
android:hint="#string/password_hint"
android:inputType="textPassword"
android:background="#drawable/apptheme_edit_text_holo_light"
/>
</android.support.design.widget.TextInputLayout>
build.gradle
android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
testOptions {
unitTests.all {
testLogging {
exceptionFormat = 'full'
}
}
}
productFlavors {
}
}
dependencies {
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services-auth:9.6.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha6'
}
Kindly help me get rid of this bug. I feel like crying. :(
UPDATE
This files can be found in generated folder. e.g for design_password_eye.xml it can be found at /app/build/intermediates/exploded-aar/com.android.support/design/25.1.0/res/drawable-v21/design_password_eye.xml
I don't know why then it's declared missing and crashing my app
UPDATE 2
manifest(app)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.r.p">
<uses-sdk tools:overrideLibrary="com.base.ui.auth" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA" />
<!-- To access Google+ APIs: -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- EXTERNAL_STORAGE permissions are optional for Android 6.0 onwards. -->
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="22" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.gcm.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gcm.permission.C2D_MESSAGE" />
<application
android:name=".activities.AppApplication"
android:allowBackup="true"
android:hardwareAccelerated="false"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:largeHeap="true"
android:screenOrientation="portrait"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:theme">
// Activities here
</application>
</manifest>
Manifest for module auth(com.base.ui.auth)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.base.ui.auth">
<application>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
//activities here
</application>
</manifest>
Styles
app module
<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/md_blue_900</item>
<item name="colorAccent">#color/dialog_color</item>
<!--
This overrides the default dark or light dialog background color.
Note that if you use a dark color here, you should set md_dark_theme to
true so text and selectors look visible
-->
<item name="md_background_color">#android:color/transparent</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">#color/app_actionBar</item>
<!--To change the text styling of options menu items</item>-->
<item name="android:itemTextAppearance">#style/itemStyle</item>
<item name="android:listPopupWindowStyle">#style/MyListPopupWindowStyle</item>
<item name="android:actionModeBackground">#color/app_actionBar</item>
<item name="android:actionModeCloseDrawable">#drawable/ic_action_close</item>
</style>
<style name="Toolbar" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#color/md_white_1000</item>
<!--<item name="android:background">#color/dark_blue</item>-->
</style>
<style name="Toolbar_Popup" parent="Base.ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">#color/md_black_1000</item>
<item name="android:background">#color/md_white_1000</item>
</style>
<style name="MyListPopupWindowStyle" parent="#android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#color/app_actionBar</item>
<item name="android:textColor">#color/md_black_1000</item>
</style>
<style name="AppTheme.NoActionBar.PR" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="colorAccent">#color/md_blue_900</item>
</style>
<style name="AppTheme.NoActionBar.PC" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#color/md_white_1000</item>
<item name="colorAccent">#color/md_blue_900</item>
</style>
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionModeOverlay">true</item>
<item name="android:actionModeBackground">#color/app_actionBar</item>
<item name="itemTextAppearance">#style/MyActionBar.MenuTextStyle</item>
</style
>
values-21
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:itemTextAppearance">#style/MyActionBar.MenuTextStyle</item>
<!--To change the background of options menu-->
<item name="android:itemBackground">#color/md_white_1000</item>
</style>
</resources>
styles for module auth
<style name="SplashTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">#color/app_background</item>
<item name="colorPrimary">#color/authui_colorPrimary</item>
<item name="colorPrimaryDark">#color/authui_colorPrimaryDark</item>
<item name="colorAccent">#color/authui_colorAccent</item>
<item name="colorButtonNormal">#color/authui_colorPrimary</item>
<item name="android:buttonStyle">#style/UI.Button</item>
<item name="android:editTextStyle">#style/UI.EditText</item>
</style>
<style name="UI.EditText">
<item name="android:textSize">16sp</item>
<item name="android:lineSpacingExtra">8sp</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:colorActivatedHighlight">#color/authui_colorPrimary</item>
<item name="android:colorFocusedHighlight">#color/authui_colorPrimary</item>
</style>

Update your Gradle Plugin to 2.3.0 if you are on Android Studio 2.3:
classpath 'com.android.tools.build:gradle:2.3.0'
If you are on Android Studio 2.2 update to 2.2.3
classpath 'com.android.tools.build:gradle:2.2.3'
Also, update your libs references to 25.2.0
https://developer.android.com/studio/releases/gradle-plugin.html

It seems that TextInputLayout try to look up the resources like design_password_eye.xml only while using the default password-toggle Drawable.
So, we can avoid Resources$NotFoundException by setting app:passwordToggleDrawable="#null"
<android.support.design.widget.TextInputLayout
android:id="#+id/text_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleDrawable="#null"
app:errorEnabled="true">

Related

Android ChipGroup IllegalArgumentException, even though using MaterialComponents theme

I'm using a com.google.android.material.chip.ChipGroup in an AppCompatActivity, but when I try to make a Chip, I'm getting java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).. I have tried every possible Theme.MaterialComponents theme (yes, even .Bridge), and I'm still getting the error. Somewhere else in the app, I'm also using a chipgroup and making new chips, and everything works fine. What am I missing here?
Relevant in MyActivity:
Chip chip = new Chip(getApplicationContext());
Relevant in MyActivity xml:
<com.google.android.material.chip.ChipGroup
android:id="#+id/filter_chips"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.appname">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:networkSecurityConfig="#xml/network_security_config"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.AppName">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="MyActivity"/>
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
</application>
</manifest>
Style:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.AppName"
parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/purple_500</item>
<item name="colorPrimaryVariant">#color/purple_700</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/teal_200</item>
<item name="colorSecondaryVariant">#color/teal_700</item>
<item name="colorOnSecondary">#color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?
attr/colorPrimaryVariant</item>
</style>
</resources>
Don't use application context, use the activity's context. Application context does not have material theme enabled in it.

Getting a "You need to use a Theme.AppCompat theme (or descendant) with this activity" error in Xamarin

I am getting the following error
You need to use a Theme.AppCompat theme (or descendant) with this activity
I am following a PluralSight course and I think I missed a crucial step somewhere, but after two days of scratching my head, I can't seem to find the obvious.
Here's my code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.companyname.bethanypieshopmobile"
android:installLocation="auto">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/BethanysTheme"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
</manifest>
Activity.cs
using Android.App;
using Android.OS;
using Android.Support.V4.View;
using Android.Support.V7.App;
using BethanyPieShopMobile.Adapters;
namespace BethanyPieShopMobile
{
[Activity(Label = "PieMenuWithTabsActivity")]
public class PieMenuWithTabsActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//the line below throws the error
SetContentView(Resource.Layout.pie_menu_tabs);
var viewPager = FindViewById<ViewPager>(Resource.Id.piePager);
var categoryFragmentAdapter = new CategoryFragmentAdapter(SupportFragmentManager);
viewPager.Adapter = categoryFragmentAdapter;
}
}
}
styles.xml
<resources>
<!-- Base application theme. -->
<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>
<style name="BethanysTheme" parent="android:Theme.Material.Light">
<item name="android:colorPrimary">#color/bethanyGreen</item>
<item name="android:colorAccent">#color/bethanyBeige</item>
</style>
<style name="BethanyGreenText" parent="TextAppearance.AppCompat">
<item name="android:textColor">#23cfa7</item>
</style>
</resources>
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/piePager" >
<android.support.v4.view.PagerTabStrip
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:paddingBottom="12dp"
android:paddingTop="10dp"
android:textColor="#000000"/>
</android.support.v4.view.ViewPager>
add theme attribute to MainActivity
[Activity(Label = "", MainLauncher = true, Theme = "#style/AppTheme")]
OR
change theme in manifest
android:theme="#style/MainTheme"
OR
in styles.xml set BethanysTheme's parent="Theme.AppCompat.Light.NoActionBar"
these links will help you
"You need to use a Theme.AppCompat theme (or descendant) with this activity." Xamarin
You need to use a Theme.AppCompat theme (or descendant) with this activity
https://forums.xamarin.com/discussion/34692/you-need-to-use-a-theme-appcompat-theme-or-descendant-with-this-activity

Why am I receiving this "You need to use a Theme.AppCompat theme (or descendant) with this activity" error?

I am having the most frustrating issue with a new Activity. I created it in the "normal" way:
Right-Click -> New -> Activity -> Empty Activity
However I am getting this annoying error when I try to launch the activity:
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I feel my question is different from the others on StackOverflow because I've done some poking around on StackOverflow as well as googling in general, but these errors seem to pop up when somebody tries to open a dialog box, not when they are simply trying to launch a new activity.
Here is my Activity Class ViewAllStudents.java:
public class ViewAllStudents extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_all_students);
}
}
I am getting the error on the setContentView(R.layout.activity_view_all_students); line.
My layout resource file activity_view_all_students.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/view_all_students_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/student_table_header" />
<ListView
android:id="#+id/student_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
My include file student_table_header.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#color/DARKOLIVEGREEN"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/student_number_header"
style="#style/StdTableHeader"
android:layout_weight="1"
android:text="#string/student_number_header"/>
<TextView
android:id="#+id/student_id_header"
style="#style/StdTableHeader"
android:text="#string/student_id_header"/>
<TextView
android:id="#+id/student_location_header"
style="#style/StdTableHeader"
android:text="#string/student_location_header"/>
<TextView
android:id="#+id/student_status_header"
style="#style/StdTableHeader"
android:text="#string/student_status_header"/>
<TextView
android:id="#+id/student_delete_header"
style="#style/StdTableHeader"
android:text="#string/student_injuries_header"/>
<TextView
android:id="#+id/student_deleted_header"
style="#style/StdTableHeader"
android:text="#string/student_deleted_header"/>
<TextView
android:id="#+id/student_last_modified"
style="#style/StdTableHeader"
android:text="#string/student_last_modified_header"/>
</LinearLayout>
Finally, my styles resource file styles.xml:
<resources>
<style name="StdTableHeader">
<item name="android:textSize">14sp</item>
<item name="android:paddingLeft">4dp</item>
<item name="android:paddingRight">4dp</item>
<item name="android:paddingTop">2dp</item>
<item name="android:paddingBottom">2dp</item>
<item name="android:layout_weight">10</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textColor">#color/WHITE</item>
<item name="android:textStyle">bold</item>
<item name="android:textAllCaps">true</item>
<item name="android:gravity">center</item>
</style>
</resources>
My AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:supportsRtl="true">
<activity
android:name=".main.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".forms.formOne"
android:label="#string/form_one_header"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".forms.formTwo"
android:label="#string/form_two_header"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".forms.formThree"
android:label="#string/form_three_header"
android:theme="#style/AppTheme.NoActionBar"
android:windowSoftInputMode="adjustPan|stateHidden" />
<activity
android:name=".main.AddStudent"
android:label="#string/title_activity_add_patient"
android:theme="#style/AppTheme.NoActionBar" />
<activity android:name=".main.ViewAllStudents"></activity>
</application>
</manifest>
Add this attribute
android:theme="#style/Theme.AppCompat.Light"
in the activity tag.
Or have the styles.xml like the following
<resources>
<!-- Base application theme. -->
<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>
</resources>
and in manifest add this attribute
android:theme="#style/AppTheme"
in the application tag.
Ok ... to make a long answer short, check your AndroidManifest.xml files. For some reason, AndroidStudio neglected to insert critical line:
android:theme="#style/AppTheme.NoActionBar"
AndroidStudio had inserted this line for all of my other activities that I have created, except for this one.
Thanks to all who took the time to help and who tolerated my ignorance.

AppCompat theme

I need your help for an issue occured about AppCompat theme. My MainActivity is derived from AppCompatActivity and the theme is declared in the Manifest but when I compile I get this error:
Java.Lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity
This is the file containing the theme:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#3F51B5</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#303F9F</item>
<!-- theme UI controls like checkboxes, text fields and switchcompat button-->
<item name="colorAccent">#00FFFF</item>
</style>
And this is manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="test_vp.test_vp" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-feature android:name="android.hardware.wifi" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<application android:label="#string/ApplicationName" android:theme="#style/MyTheme">
</application>
</manifest>
Do You know how can I solve it?
Thank You in advance
Change the first line of code you show:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
to
<style name="MyTheme" parent="#android:style/Theme.AppCompat.Light.NoActionBar">
Also, inside this style definition is where you put children definition to only there you define characteristics like color etc. It's a case of nested definition. Let me try to clear things:
First you define your main style which refers to your secondary style:
<style name="MyTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
Second, in this same xml you're working, below you define this child style, it is inside this where you choose colors etc. Pay attention with the name of this child theme - must be the same you referenced on parent:
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.ActionBar">
<item name="colorPrimary">#3F51B5</item>
</style>
In some cases you will have to go deep inside this nesting, defining things by detailed steps. To resume: you can't change things directly, have to specify every detailed portion where you want to customize.
try:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.NoActionBar"></style>
It's in support lib, so ommit the "android:" part.

android action bar overlay issue

all, I tired to make a action bar overlay the layout of my activity. I am also use support library to support android 2.1 and above, the layout of my activity is as follows:
<!-- activity_display_message.xml in layout folder -->
<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="?attr/actionBarSize"
tools:context=".DisplayMessageActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
The manifest.xml is like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher">
android:theme="#style/CustomActionBarTheme" >
<!-- some code for main activity -->
<activity
android:name="com.example.myfirstapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.MainActivity" />
</activity>
</application>
</manifest>
The styles.xml which defines CustomActionBarTheme is as follows:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<!-- Support library compatibility -->
<!-- Setting values in the default namespace affects API levels 7-13 -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="background">#color/orange</item>
<item name="titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
<!-- ActionBar tabs text -->
<style name="MyActionBarTabText"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
<!-- The textColor property is backward compatible with the Support Library -->
</style>
</resources>
Now the problem when applied CustomActionBarTheme is that the text (passed from main activity) which supposed to be displayed in the TextView of display_message_activity disappeared, so I am guessing if it is due to the overlay action bar that covers the text message, and so anyone has any idea how to solve the issue?
cheers
I think that's the cause that doesn't show your text and to solve your problem you should set margin top for TextView with the value: ?attr/actionBarSize
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize" />
I hope you have solved your problem and this is a correct answer :)

Categories

Resources