java - How to hide action bar on HTC one using Holo.NoActionBar theme -


my app uses android them holo.noactionbar theme hide action bar , display activity .

this works fine on emulator , nexus 4 ,device actionbar hidden.

however when run on htc 1 , ignores android theme settings , displays action bar. might displayed on other samsung or sony devices have custom oem skins. have made sure there no references action bar or menu options in activity java file or android manifest file.

so googled how hide action bar , tried how hide action bar before activity created, , show again?

and wrote code

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); getwindow().requestfeature(window.feature_action_bar); getactionbar().hide(); setcontentview(r.layout.activity_my); 

and http://developer.android.com/guide/topics/ui/actionbar.html

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); actionbar actionbar = getsupportactionbar(); actionbar.hide(); setcontentview(r.layout.activity_my); 

however in both cases ide displays warning saying method invocation'actionbar.hide()' may produce 'java.lang.nullpointerexception'

"this inspection analyzes method control , data flow report possible conditions true or false, expressions value statically proven constant , situations can lead nullability contract violations"

although new android development know nullpointerexception should not ignored.

but in activity , important hide action bar.

how modify code not error prone??

update: , why holo.noactionbar not working htc 1 . still displaying action bar, while installing same apk not display action bar on nexus 4

android manifest:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"  package="com.xxxxxxxx.xxxxxxxxx" >  <uses-permission android:name="android.permission.vibrate" />  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name=".myactivity"         android:label="@string/app_name"         android:screenorientation="portrait" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity>     .     .     lots of non-relevant activities     .     .      <activity         android:name=".setting"         android:label="@string/title_activity_setting"         android:parentactivityname=".myactivity"         android:screenorientation="portrait">         <meta-data             android:name="android.support.parent_activity"             android:value="com.xxxxxxxxx.xxxxxxxxxx.myactivity" />     </activity>     <activity         android:name=".t1"         android:screenorientation="portrait"     >     </activity>     <activity         android:name=".t2"         android:screenorientation="portrait"     >     </activity>     <activity         android:name=".t3"         android:screenorientation="portrait"         >     </activity>     <activity         android:name=".t4"         android:screenorientation="portrait"          >     </activity>     <activity         android:name=".t5"         android:label="@string/title_activity_t5"         android:screenorientation="portrait"         android:parentactivityname=".myactivity" >         <meta-data             android:name="android.support.parent_activity"             android:value="com.xxxxxxxxxx.xxxxxxxxxx.myactivity" />     </activity> </application>  </manifest> 

t1.java, without actionbar.hide()

import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.relativelayout;   public class t1 extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_t1);      relativelayout rl = (relativelayout) findviewbyid(r.id.rel1);     rl.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent newactivity= new intent(getapplicationcontext(), t2.class);             startactivity(newactivity);         }     }); }   } 

and t2,t3,t4,t5 have similar code

layout file:

<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:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context="com.xxxxxxxxxx.xxxxxxxx.t1" android:background="@drawable/finalp2" android:id="@+id/rel1">  <imageview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/imageview"     android:layout_margintop="40dp"     android:background="@drawable/bat"     android:layout_alignparenttop="true"     android:layout_alignparentleft="true"     android:layout_alignparentstart="true"     android:layout_marginleft="40dp" />  <imageview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/imageviewbottom"     android:background="@drawable/bat"     android:layout_alignparentbottom="true"     android:layout_alignparentright="true"     android:layout_alignparentend="true"     android:layout_marginright="40dp"     android:layout_marginbottom="42dp" />  <imageview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/imageview2"     android:layout_alignparenttop="true"     android:layout_alignparentright="true"     android:layout_alignparentend="true"     android:background="@android:drawable/ic_media_pause" />  <imageview     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:id="@+id/imageview4"     android:layout_below="@+id/imageview"     android:layout_torightof="@+id/imageview"     android:layout_toendof="@+id/imageview"     android:layout_margintop="112dp"     android:background="@drawable/ball1" />   </relativelayout> 

how selected theme : http://s16.postimg.org/6vuyjhwth/noactionbar.png

i have not created other style.xml file, did miss something?? if did miss how working fine on nexus 4 , why showing without action bar in ide?

my app use sdk version 15 , higher

your activity t1 not have theme applied in androidmanifest.xml therefore uses default application - in case, @style/apptheme includes action bar. set theme in manifest:

<activity     android:name=".t1"     android:screenorientation="portrait"     android:theme="@android:style/theme.holo.light.noactionbar" > </activity> 

or make new theme no action bar case:

<style name="apptheme.noactionbar" parent="android:theme.holo.light.noactionbar">     <!-- customize theme here. --> </style> 

and use it:

<activity     android:name=".t1"     android:screenorientation="portrait"     android:theme="@style/apptheme.noactionbar" > </activity> 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -