Remove Action Bar Android - android

Hi to android stack overflow communities,
I want to remove the action bar which contain the title and the three dots. I have tried some of the solutions such as android:theme="#android:style/Theme.NoTitleBar" but, the app went crash.
Is there any possible other solution? Thanks

This is the nuclear option.
Replace
public class MainActivity extends ActionBarActivity
with
public class MainActivity extends Activity
in all the Activitys where you don't want ActionBar.
And to remove the three-dots button, add
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
return false;
}
to your Activity.
Try this. This will work.

You have to use Activity not ActionBarActivity. So extends your javaclass from Activity. For removing the three dots remove onCreateOptionsMenu method from your Activity.

Create Your code like this
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Enter this line android:theme="#android:style/Theme.Black.NoTitleBar" in Activity

You just need to call function
getActionBar().hide();
Tthis will hide action bar for you simply.

Related

How Up Navigation works

I've implemented inside my app the Up Navigation button in this way, inside my AndroidManifest.xml I wrote this:
<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/AppTheme">
<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=".EventDetails"
android:label="#string/category_events"
android:parentActivityName=".MainActivity"
android:screenOrientation="portrait"/>
</application>
I didn't do anything else and everything works very good.
I read the official documentation and about the
android:parentActivityName=".MainActivity"
they say:
With the parent activity declared this way, you can navigate Up to the appropriate parent using the NavUtils APIs, as shown in the following sections.
This is my child activity code:
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class EventDetails extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Set the content of the activity
setContentView(R.layout.event_details);
}
}
So you can see that I don't implement NavUtils APIs, etc...
Now my question is this, why everything works?
NavUtils are a set of convenience methods for doing certain tasks, like launching your parent as a new task. They are not required for any android app, and there is basic functionality like back stack navigation present without any need to use them.
Also, I see you tagged this fragments- it has nothing to do with fragments. NavUtils is about navigating between Activities, not Fragments of a single Activity.

"App has stopped" when changing between activities

Hello everyone this is my first android coding and im trying to switch between activities, but i cant simply find where is my mistake.
Main here;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
protected void start()
{
Intent k= new Intent(MainActivity.this, Try.class);
startActivity(k);
finish();
}
And My manifest is here and my second activity name is "Try";
<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/AppTheme">
<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="com.example.ege.intent.Try"
android:label="#string/app_name" >
</activity>
</application>
Thanks.
I think;
May your class package name is wrong but there should be more information about crash.
Change android:name="com.example.ege.intent.Try"
with Try.class location, if it is same in Manifest.
Just try to Change android:name=".Try"
If you put your error or your log details, I can help you
the method "start()" is unused. use it in "onCreate()" method .
you may add a button . swtich activities by listening the click.
Where do you call start()?. Manifest seems okay but check if your package is right, anyway try would do the same, MainActivity lacks a closing semicolon }

Android ActionBar/Toolbar Disappears in my App

So I have an app. It has 3 activities at the moment... I am using intents to launch the activities from one and another
MainActivity > ChallongeLogin > ChallongeEvents
In my MainActivity and my ChallongeLogin, there is a large bar at the top of the app that lists the name of my app. However, when I eventually read the ChallongeEvents, this bar disappears... I don't remember doing anything special to make this bar disappear. Why did it go away?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testing.testingapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:screenOrientation="portrait"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name=".ChallongeLogin" />
<activity
android:screenOrientation="portrait"
android:name=".ChallongeEvents" />
</application>
</manifest>
According to your requirement you must extends AppCompatActivity instead of Activity .
public class ActivityName extends AppCompatActivity {
// ...
}
AppCompatActivity is from the appcompat-v7 library. Principally, this
offers a backport of the action bar. Since the native action bar was
added in API Level 11, you do not need AppCompatActivity for that.
However, current versions of appcompat-v7 also add a limited backport
of the Material Design aesthetic, in terms of the action bar and
various widgets. There are pros and cons of using appcompat-v7, well
beyond the scope of this specific Stack Overflow answer.
Reference
Activity, AppCompatActivity, FragmentActivity, and ActionBarActivity: When to Use Which?
It is called ActionBar/ToolBar.
Extend the AppCompatActivity class instead of plain Activity class in that activity's java class.

android activity not full screen Theme.Dialog app has stopped

I made second activity with ImageButton. It was displayed fine with white space around. I want to make it not full screen. Here stackoverflow answers said add android:theme="#android:style/Theme.dialog". So now my manifest:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<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=".Main2Activity"
android:theme="#android:style/Theme.Dialog" >
</activity>
</application>
But now app crashs when Main2Activity is called by startActivity. Why?
I think you might have extended the AppCompatActivity class or some other class for Main2Activity class..try extending only the Activity class for Main2Activity
Public class Main2Activity extends Activity
add this requestWindowFeature(Window.FEATURE_NO_TITLE); before loading the setcontent
You might have extended the AppCompatActivity class or some other class for Main2Activity class. If so, change
android:theme="#android:style/Theme.Dialog"
to
android:theme="#style/Theme.AppCompat.Dialog"
Then it will work perfectly.

Android: Remove the top bar from an app?

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.

Categories

Resources