I have been trying to add google-cast to my Android app that plays videos using Exoplayer. The app has one single activity withTheme.Leanback theme and the same UI is used for both Phones and Android TV.
To add casting support on phones, I have modified in the player view and I added the cast button as below:
<androidx.mediarouter.app.MediaRouteButton
android:id="#+id/media_route_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:scaleY="0.8"
android:scaleX="0.8"
android:background="#android:color/transparent"
android:mediaRouteTypes="user"
android:visibility="visible" />
When I run the application I get the following error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.EXAMPLE.PACKAGE, PID: 10661
android.view.InflateException: Binary XML file line #76 in com.EXAMPLE.PACKAGE:layout/activity_player: Binary XML file line #76 in com.EXAMPLE.PACKAGE:layout/activity_player: Error inflating class androidx.mediarouter.app.MediaRouteButton
Caused by: android.view.InflateException: Binary XML file line #76 in com.EXAMPLE.PACKAGE:layout/activity_player: Error inflating class androidx.mediarouter.app.MediaRouteButton
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at com.EXAMPLE.PACKAGE.fragment.PlayerFragment.onCreateView(PlayerFragment.java:162)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: java.lang.IllegalArgumentException: background can not be translucent: #0
at androidx.core.graphics.ColorUtils.calculateContrast(ColorUtils.java:161)
at androidx.mediarouter.app.MediaRouterThemeHelper.getControllerColor(MediaRouterThemeHelper.java:177)
at androidx.mediarouter.app.MediaRouterThemeHelper.getRouterThemeId(MediaRouterThemeHelper.java:313)
at androidx.mediarouter.app.MediaRouterThemeHelper.createThemedButtonContext(MediaRouterThemeHelper.java:107)
at androidx.mediarouter.app.MediaRouteButton.<init>(MediaRouteButton.java:153)
at androidx.mediarouter.app.MediaRouteButton.<init>(MediaRouteButton.java:149)
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
at android.view.LayoutInflater.createView(LayoutInflater.java:852)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:1004)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:959)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1121)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:1124)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)
at android.view.LayoutInflater.inflate(LayoutInflater.java:680)
at android.view.LayoutInflater.inflate(LayoutInflater.java:532)
at com.EXAMPLE.PACKAGE.fragment.PlayerFragment.onCreateView(PlayerFragment.java:162)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2963)
at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:518)
at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:282)
at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2189)
at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2100)
at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:524)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I have tried setting the background of the castbusston transparent as was suggested in few places online but that did not help.
I can have several other Image Button and Text Buttons that are working fine.
I tried using <MediaRouteButton instead of <androidx.mediarouter.app.MediaRouteButton. This way the button will be showed and greyed out in the player layout however, when I try to intitize the cast context as below:
mMediaRouteButton = (MediaRouteButton) mView.findViewById(R.id.media_route_button);
CastButtonFactory.setUpMediaRouteButton(mContext, mMediaRouteButton);
mCastContext = CastContext.getSharedInstance(mContext);
I get the following error:
java.lang.ClassCastException: android.app.MediaRouteButton cannot be cast to androidx.mediarouter.app.MediaRouteButton
I have been puzzled by this issue for couple of days. Thank you very much in advance for your kind comments and suggestion.
Make sure that you have included the dependency that contains that class in your module's list of dependencies, such as:
implementation "androidx.mediarouter:mediarouter:1.2.6"
(or another version as appropriate)
The issue was that the primaryColor of the app theme that I was using had transparency channel, ie, #3d000000. However MediaRouteButton that is taking the primaryColor of theme needs a color without transparency channel such as #000000. So I resolved the issue as follow:
<style name="AppTheme" parent="#style/Theme.Leanback">
<!-- Primary Color -->
<item name="colorPrimary">#color/defaultColor</item>
</style>
where I defined <color name="defaultColor">#000000</color>
Later on I encountered another issue that MediaCastButton can only be used with AppCompat decedent theme. The solution for me was to change the app theme to an Theme.AppCompat.Light.NoActionBar theme and modify it to look like Theme.Leanback as below:
<style name="AppTheme1" parent="#style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/blackColor</item>
<item name="android:windowBackground">#color/blackColor</item>
<!-- <item name="mediaRouteButtonTint">#color/whiteColor</item>-->
<item name="baseCardViewStyle">#style/Widget.Leanback.BaseCardViewStyle</item>
<item name="imageCardViewStyle">#style/Widget.Leanback.ImageCardViewStyle</item>
<item name="imageCardViewImageStyle">#style/Widget.Leanback.ImageCardView.ImageStyle</item>
<item name="imageCardViewTitleStyle">#style/Widget.Leanback.ImageCardView.TitleStyle</item>
<item name="imageCardViewContentStyle">#style/Widget.Leanback.ImageCardView.ContentStyle</item>
<item name="imageCardViewBadgeStyle">#style/Widget.Leanback.ImageCardView.BadgeStyle</item>
<item name="imageCardViewInfoAreaStyle">#style/Widget.Leanback.ImageCardView.InfoAreaStyle</item>
<item name="browsePaddingStart">#dimen/lb_browse_padding_start</item>
<item name="browsePaddingEnd">#dimen/lb_browse_padding_end</item>
<item name="browsePaddingTop">#dimen/lb_browse_padding_top</item>
<item name="browsePaddingBottom">#dimen/lb_browse_padding_bottom</item>
<item name="browseRowsMarginStart">#dimen/lb_browse_rows_margin_start</item>
<item name="browseRowsMarginTop">#dimen/lb_browse_rows_margin_top</item>
<item name="browseRowsFadingEdgeLength">#dimen/lb_browse_rows_fading_edge</item>
<!-- <item name="headersVerticalGridStyle">#style/Widget.Leanback.Headers.VerticalGridView</item>-->
<!-- <item name="headerStyle">#style/Widget.Leanback.Header</item>-->
<!-- <item name="sectionHeaderStyle">#style/Widget.Leanback.Header.Section</item>-->
<item name="rowsVerticalGridStyle">#style/Widget.Leanback.Rows.VerticalGridView</item>
<item name="rowHorizontalGridStyle">#style/Widget.Leanback.Row.HorizontalGridView</item>
<item name="itemsVerticalGridStyle">#style/Widget.Leanback.GridItems.VerticalGridView</item>
<item name="browseTitleViewLayout">#layout/lb_browse_title</item>
<item name="browseTitleTextStyle">#style/Widget.Leanback.Title.Text</item>
<item name="browseTitleIconStyle">#style/Widget.Leanback.Title.Icon</item>
<item name="browseTitleViewStyle">#style/Widget.Leanback.TitleView</item>
<item name="rowHeaderStyle">#style/Widget.Leanback.Row.Header</item>
<item name="rowHeaderDescriptionStyle">#style/Widget.Leanback.Row.Header.Description</item>
<item name="rowHoverCardTitleStyle">#style/Widget.Leanback.Row.HoverCardTitle</item>
<item name="rowHoverCardDescriptionStyle">#style/Widget.Leanback.Row.HoverCardDescription</item>
<item name="rowHeaderDockStyle">#style/Widget.Leanback.Row.HeaderDock</item>
<!-- <item name="searchOrbViewStyle">#style/Widget.Leanback.SearchOrbViewStyle</item>-->
<item name="detailsDescriptionTitleStyle">#style/Widget.Leanback.DetailsDescriptionTitleStyle</item>
<item name="detailsDescriptionSubtitleStyle">#style/Widget.Leanback.DetailsDescriptionSubtitleStyle</item>
<item name="detailsDescriptionBodyStyle">#style/Widget.Leanback.DetailsDescriptionBodyStyle</item>
<item name="detailsActionButtonStyle">#style/Widget.Leanback.DetailsActionButtonStyle</item>
<!-- Attributes used for styling of a playback -->
<item name="playbackPaddingStart">#dimen/lb_playback_controls_margin_start</item>
<item name="playbackPaddingEnd">#dimen/lb_playback_controls_margin_end</item>
<item name="playbackMediaItemPaddingStart">#dimen/lb_playback_media_row_horizontal_padding</item>
<item name="playbackMediaListHeaderStyle">#style/Widget.Leanback.PlaybackMediaListHeaderStyle</item>
<item name="playbackMediaItemRowStyle">#style/Widget.Leanback.PlaybackMediaItemRowStyle</item>
<item name="playbackMediaItemSeparatorStyle">#style/Widget.Leanback.PlaybackMediaItemSeparatorStyle</item>
<item name="playbackMediaListHeaderTitleStyle">#style/Widget.Leanback.PlaybackMediaListHeaderTitleStyle</item>
<item name="playbackMediaItemDetailsStyle">#style/Widget.Leanback.PlaybackMediaItemDetailsStyle</item>
<item name="playbackMediaItemNumberViewFlipperStyle">#style/Widget.Leanback.PlaybackMediaItemNumberViewFlipperStyle</item>
<item name="playbackMediaItemNumberViewFlipperLayout">#layout/lb_media_item_number_view_flipper</item>
<item name="playbackMediaItemNumberStyle">#style/Widget.Leanback.PlaybackMediaItemNumberStyle</item>
<item name="playbackMediaItemNameStyle">#style/Widget.Leanback.PlaybackMediaItemNameStyle</item>
<item name="playbackMediaItemDurationStyle">#style/Widget.Leanback.PlaybackMediaItemDurationStyle</item>
<item name="playbackControlsButtonStyle">#style/Widget.Leanback.PlaybackControlsButtonStyle</item>
<item name="playbackControlButtonLabelStyle">#style/Widget.Leanback.PlaybackControlLabelStyle</item>
<item name="playbackControlsTimeStyle">#style/Widget.Leanback.PlaybackControlsTimeStyle</item>
<item name="playbackControlsActionIcons">#style/Widget.Leanback.PlaybackControlsActionIconsStyle</item>
<item name="playbackControlsAutoHideTimeout">#integer/lb_playback_controls_show_time_ms</item>
<item name="playbackControlsAutoHideTickleTimeout">#integer/lb_playback_controls_tickle_timeout_ms</item>
<item name="errorMessageStyle">#style/Widget.Leanback.ErrorMessageStyle</item>
<item name="defaultSearchColor">#color/lb_default_search_color</item>
<item name="defaultSearchIconColor">#color/lb_default_search_icon_color</item>
<item name="defaultSearchBrightColor">?attr/defaultSearchColor</item>
<item name="defaultSearchIcon">#drawable/lb_ic_in_app_search</item>
<item name="defaultSectionHeaderColor">?attr/defaultSearchColor</item>
<item name="overlayDimMaskColor">#color/lb_view_dim_mask_color</item>
<item name="overlayDimActiveLevel">#fraction/lb_view_active_level</item>
<item name="overlayDimDimmedLevel">#fraction/lb_view_dimmed_level</item>
</style>
Related
I am having a problem implementing Material Button and I get the following error shown below. I have tried different solutions found on stackoverflow but can't seem to know why it keeps showing me this error. Any help would be much appreciated. Thanks in advance
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.app.lifeadvicequotes, PID: 8603
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.app.lifeadvicequotes/com.app.lifeadvicequotes.MainActivity}: android.view.InflateException: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Error inflating class com.google.android.material.button.MaterialButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4111)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4277)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:103)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2443)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8751)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
Caused by: android.view.InflateException: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Error inflating class com.google.android.material.button.MaterialButton
Caused by: android.view.InflateException: Binary XML file line #73 in com.app.lifeadvicequotes:layout/activity_main: Error inflating class com.google.android.material.button.MaterialButton
This is my style 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>
<item name="android:textColorPrimary">#color/text_color_primary</item>
</style>
<!-- Base application theme. -->
<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
<style name="AppTheme.Button" parent="android:Widget.Material.Button">
<item name="colorButtonNormal">#FFFFFF</item>
<item name="android:textColor">#000000</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="NavigationDrawerStyle">
<item name="android:textSize">16sp</item>
</style>
</resources>
The issue might be from parent="android:Widget.Material.Button" try changing it to parent="Widget.MaterialComponents.Button or parent="Base.Widget.AppCompat.Button" if you haven't imported Material Components library
I am attempting to upgrade my react-native version to 0.59.10. My app crashes upon attempt to debug and I get this error when running adb logcat.
E/AndroidRuntime( 9402): Process: com.attendance, PID: 9402
E/AndroidRuntime( 9402): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.attendance/com.attendance.MainActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }```
This is my current style code:
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:navigationBarColor">#color/primary_dark</item>
<item name="android:colorPrimary">#color/primary</item>
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<item name="android:colorAccent">#color/accent</item>
<item name="android:windowBackground">#color/primary_dark</item>
</style>
<application
android:name=".MainApplication"
android:allowBackup="false"
android:label="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:theme="#style/AppTheme">
I can get the app to run by simply changing android:theme to
android:theme="#style/Theme.AppCompat.Light.NoActionBar">
but the theme is not the same as before.
I have tried implementing all the properties in the initial error but then the app never loads.
Any ideas on how to get my app to load and have the original themes?
Modified styles to:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorPrimary">#color/primary</item>
<item name="colorAccent">#color/accent</item>
<item name="android:navigationBarColor">#color/primary_dark</item>
</style>
</resources>```
and this resolved the issue.
Here's my IDE and gradle plugin version:
AndroidStudio:3.1.4
classpath 'com.android.tools.build:gradle:3.1.4'
In my project,I have a main module and a sub module.
In my sub module, I have a values.xml like following:
<style name="OmActivityAnim">
<item name="android:activityOpenEnterAnimation">#anim/om_base_slide_from_right</item>
<item name="android:activityOpenExitAnimation">#anim/om_base_slide_to_left</item>
<item name="android:activityCloseEnterAnimation">#anim/om_base_slide_from_left</item>
<item name="android:activityCloseExitAnimation">#anim/om_base_slide_to_right</item>
</style>
<style name="OmActivityAnim2">
<item name="android:activityOpenEnterAnimation">#anim/om_base_show_dialog_anim</item>
<item name="android:activityOpenExitAnimation">#anim/om_base_dismiss_dialog_anim</item>
<item name="android:activityCloseEnterAnimation">#anim/om_base_show_dialog_anim</item>
<item name="android:activityCloseExitAnimation">#anim/om_base_dismiss_dialog_anim</item>
</style>
but when I run my Main module I just got
AAPT: error: style attribute '#android:attr/activityOpenEnterAnimation' not found.
following errors
error: style attribute '#android:attr/activityOpenEnterAnimation' not found.
error: style attribute '#android:attr/activityOpenExitAnimation' not found.
error: style attribute '#android:attr/activityCloseEnterAnimation' not found.
error: style attribute '#android:attr/activityCloseExitAnimation' not found.
error: style attribute '#android:attr/activityOpenEnterAnimation' not found.
error: style attribute '#android:attr/activityOpenExitAnimation' not found.
error: style attribute '#android:attr/activityCloseEnterAnimation' not found.
error: style attribute '#android:attr/activityCloseExitAnimation' not found.
But, why my android:activityOpenEnterAnimation changes to '#android:attr/activityOpenEnterAnimation'?
Just add '#' before 'android'.Because '#android' is the exact annotation to write the theme reference to another resource.
Edit your code from
<style name="OmActivityAnim">
<item name="android:activityOpenEnterAnimation">#anim/om_base_slide_from_right</item>
<item name="android:activityOpenExitAnimation">#anim/om_base_slide_to_left</item>
<item name="android:activityCloseEnterAnimation">#anim/om_base_slide_from_left</item>
<item name="android:activityCloseExitAnimation">#anim/om_base_slide_to_right</item>
</style>
<style name="OmActivityAnim2">
<item name="android:activityOpenEnterAnimation">#anim/om_base_show_dialog_anim</item>
<item name="android:activityOpenExitAnimation">#anim/om_base_dismiss_dialog_anim</item>
<item name="android:activityCloseEnterAnimation">#anim/om_base_show_dialog_anim</item>
<item name="android:activityCloseExitAnimation">#anim/om_base_dismiss_dialog_anim</item>
</style>
to
<style name="OmActivityAnim">
<item name="#android:activityOpenEnterAnimation">#anim/om_base_slide_from_right</item>
<item name="#android:activityOpenExitAnimation">#anim/om_base_slide_to_left</item>
<item name="#android:activityCloseEnterAnimation">#anim/om_base_slide_from_left</item>
<item name="#android:activityCloseExitAnimation">#anim/om_base_slide_to_right</item>
</style>
<style name="OmActivityAnim2">
<item name="#android:activityOpenEnterAnimation">#anim/om_base_show_dialog_anim</item>
<item name="#android:activityOpenExitAnimation">#anim/om_base_dismiss_dialog_anim</item>
<item name="#android:activityCloseEnterAnimation">#anim/om_base_show_dialog_anim</item>
<item name="#android:activityCloseExitAnimation">#anim/om_base_dismiss_dialog_anim</item>
</style>
This will solve your issue.
I use Google's support libraries of version 23.1.0.
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:preference-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
I am reusing a theme file that worked with versions of the support libraries prior to the introduction of material design.
<style name="AppTheme.StatusBarOverlay.Main" parent="#style/AppTheme.Main">
<item name="android:windowContentOverlay">#null</item>
</style>
<style name="AppTheme.Main" parent="#style/AppBaseTheme.Main">
<item name="windowActionBar">false</item>
</style>
<style name="AppBaseTheme.Main" parent="#style/Theme.AppCompat.Main">
<item name="colorPrimary">#color/main_color</item>
<item name="colorPrimaryDark">#color/main_color_dk</item>
</style>
<style name="Theme.AppCompat.Main" parent="#style/Base.Theme.AppCompat.Main" />
<style name="Base.Theme.AppCompat.Main" parent="#style/Base.V7.Theme.AppCompat" />
<style name="Theme.CustomDialog" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#drawable/trans_draw</item>
<item name="android:windowNoTitle">true</item>
</style>
I made my MainActivity use the style by setting the theme in the manifest
<activity
android:name=".activities.MainActivity"
android:label="#string/title_activity_main"
android:theme="#style/AppTheme.StatusBarOverlay.Main" >
</activity>
When the action bar was retrieved
ActionBar actionBar = getSupportActionBar();
the following exception was raised.
Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features: { windowActionBar: false, windowActionBarOverlay: false, android:windowIsFloating: false, windowActionModeOverlay: false, windowNoTitle: false }
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:423)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatDelegateImplV7.initWindowDecorActionBar(AppCompatDelegateImplV7.java:173)
at android.support.v7.app.AppCompatDelegateImplBase.getSupportActionBar(AppCompatDelegateImplBase.java:89)
at android.support.v7.app.AppCompatActivity.getSupportActionBar(AppCompatActivity.java:79)
at com.dynamicwebapac.commerce.mobile.custom.CustomActivity.setupActionBar(CustomActivity.java:39)
at com.dynamicwebapac.commerce.mobile.custom.CustomActivity.onCreate(CustomActivity.java:25)
at com.dynamicwebapac.commerce.mobile.activities.MainActivity.onCreate(MainActivity.java:181)
at android.app.Activity.performCreate(Activity.java:5933)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
What happened to the Android support library after material design was introduced? How can I solve my current problem?
Using the new material support library, we set up themes like this styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Also in the manifest
android:theme="#style/AppTheme"
And then we use the Toolbar as the action bar .Do this in your parent layout
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
And we set it up in our Java source using
Toolbar toolbar=(Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Don't worry it happens with most of us. I'd like to start with reason of this problem.
The Material Design is in the favour of using Toolbar which is more flexible,...etc hence the themes or styles provided by AppCompat library are without an ActionBar or you can say a support ActionBar is provided and hence e need to disable the system default ActionBar.
Now follow any of the 2 steps below as suggested by Colns Abt:
Add any style which has NoActionBar at the ending like Theme.AppCompat.NoActionBar
OR
Add the following lines in your custom style
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
Further follow steps given by Colns Abt.
I applied the below style for timepicker:
<style name="MyHoloTimePicker" parent="#android:style/Widget.DeviceDefault.DatePicker">
<item name="android:textColor">#2eb135</item>
<item name="android:textSize">16sp</item>
<item name="android:textStyle">normal</item>
</style>
I have set the above style to time picker in xml as follows:
<TimePicker
android:id="#+id/pickertime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/MyHoloTimePicker"
/>
I got the below exception:
12-03 01:12:26.742: E/AndroidRuntime(9279): Caused by: java.lang.NullPointerException <br>
12-03 01:12:26.742: E/AndroidRuntime(9279): Caused by: java.lang.reflect.InvocationTargetException
How can I sort out this issue?
There is no Widget.DeviceDefault.DatePicker. Try setting the parent to:
parent="#android:style/Widget.DatePicker"
EDIT:
I found that the DeviceDefault themes are in a different file and can by used by API 14+.
themes_device_defaults.xml