I'm trying to remove the top bar from the app. I try to write in the xml file
<activity
android:theme="#android:style/Theme.Black.NoTitleBar">
</activity>
But it give me the error:
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
I also try do use the code after OnCreate method:
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.your_layout_name_here);
But it also crash....how can i do? Thanks!
You could keep the default theme in AndroidManifest file. There is only one reason you are seeing the title bar.
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And you could add
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
It is because your activity is extending ActionBarActivity. You could replace by extending Activity for your activity.
public class MainActivity extends Activity
I hope this will solve your problem.
Related
I'm using a toolbar for my entire application. So I have set up my application Theme to Theme.AppCompat.Light.NoActionBar But I need to show a alert dialog in a part of my app. When I try to show alert dialog I'm getting Runtime error about Theme.Appcompat
My manifest.xml file
<application
android:allowBackup="true"
android:icon="#drawable/app_icon2"
android:label="#string/app_name"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
>
<activity
android:name="com.project.project.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.project.project.StActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="#string/app_name">
<intent-filter >
<action android:name="android.intent.action.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
What should i do
Thanks for help
It's hard to tell without seeing the code where you actually create the Dialog, but my guess is that you're either:
Not using the Activity as the Context when you create the Dialog. The Activity context holds the theme; if you tried using the Application it wouldn't get the right theme.
Setting your Dialog theme to something that doesn't inherit from Theme.AppCompat (using the constructor, setStyle() or ContextThemeWrapper).
Either way, the Dialog doesn't get the required attributes provided by Theme.AppCompat.
I have an activity as a child within a navigation drawer parent activity, any time the orientation of the pages changes the page has to be reloaded again.
public class ApplicationsClass extends NavigationDrawer implements LoaderCallbacks<Cursor> {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLayoutInflater().inflate(R.layout.main_list_activity, frameLayout);
if (savedInstanceState == null) {
//I do my stuffs here
}
}
...
}
In my AndroidManifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="22" />
<!-- Main activity. -->
<application
android:largeHeap="true"
android:allowBackup="true"
android:theme="#style/AppTheme"
android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode">
<!-- Register Activity -->
<activity
android:name=".ApplicationsClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
...
</application>
I have tried adding android:configChanges="orientation|keyboard|keyboardHidden|screenSize|screenLayout|uiMode" to my application tag in the androidmanifest as some articles suggested but to no avail. Please is there a way to stop reloading the page upon orientation changes in android. I would be grateful if someone could help. Thanks in advance.
UPDATE
I had also tried adding android:configChanges="orientation|screenSize" to my activity within the androidmanifest.xml but to no avail.
I just realized that adding android:configChanges="orientation|screenSize|keyboardHidden" only works when i am had not extended the class from the navigationdrawer and thereby making it a fragment with the navigationdrawer class. This only works when it is not in a fragment layout form.
You need to declare android:configChanges="orientation|screenSize" in activity tag not in application tag
<activity
android:name=".ApplicationsClass"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
When i use the Label attribute in the manifest for an activity, it does not show in the recent application list. Code for activity in manifest file is:
<activity
android:name=".MainActivity"
android:screenOrientation="portrait"
android:theme="#style/MyTheme"
android:icon="#drawable/ic_launcher"
android:label=""
>
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
when i use android:label="#string/app_name" , then it start showing in the recent tab, but i dont want activity label.
Your application is not visible in recent apps list because label of your main activity is empty.
Change
<activity... android:label="">
To
<activity... android:label="#string/some_name">
Edit:
If you don't want to show label for your activity then do the following.
You must set android:label="#string/some_name" in <activity> tag
And then write getActionBar().setDisplayShowTitleEnabled(false); in onCreate() method of your activity you want to hide label of.
This will let you hide the activity label and will show your app in recent apps list as well.
Here I am getting this screen every time just like a splash for few seconds and then opening the home activity.I don't want to this screen in my app. How to fix it.
Here is my manifest file
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.asdf.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
For your Information, I am using Support Library for developing.
I changed the app Style to "#android:style/Theme.Translucent.NoTitleBar" then this screen is not showing but It has the impact on other UI components of the same App like.. Spinner, text-view etc.
Add this line in your style.xml
<style name="AppTheme" parent="android:style/Theme.Holo">
<item name="android:windowDisablePreview">true</item>
try this..well previous one should work.It worked for me
If you want to remove the title bar, then use the following in your Activity initialization:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
...
move Intent-filter code to whichever activity of your application. and remove that activity code.
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Hope it will work
I have an Android app which has a main activity and 3 Fragments which are tabs. I would like the application to remain in portrait mode at all times but I can't seem to get this working. This is what I have tried, as per another stack overflow post, but I'm not sure what I'm doing wrong....does it need to be different if using fragments?
<activity
android:name="com.tutorial.test.activities.act1"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Thank you!!
Edit: The ViewPager is on the FragmentActivity for which I am setting the screenOrientation as above.
Try this..
You can try with programmatically.
After rootView in your java add this line getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
For Ex:
View rootView = inflater.inflate(R.layout.activityxml, container, false);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
And also in your manifest change it android:configChanges="orientation|keyboardHidden" as android:configChanges="keyboardHidden"
<activity
android:name="com.tutorial.test.activities.act1"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden" >
Orientation attribute is per activity so you can declare the orientation for only the activity that contains the fragment so that it is in landscape and the rest of the activities will remain as they are.
getActivity().setRequestedOrientation(
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
or you can declare in the manifest
<activity android:name=".Control" android:screenOrientation="portrait"></activity>