You can hide the action bar at runtime by calling hide(). For example:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
So it can be hidden after being generated.
How to prevent it from being generated?
You have to set a your activity's theme to one with no ActionBar. Check .NoActionBar in your current theme.
For example:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>
Related
My objective is removing the orange bar thar has the label "App name".
Currently I have a top_app_bar and bottom_nav_bar. As far as I know the orange bar is generated by the bottom nav bar.
This is the bottom nav bar implementation in the activity_main.
This is the top app bar implementation in the activity_main.
The top bar is called ActionBar. The ActionBar is a part of the default layout of the theme you are using.
Method 1:
You can hide the ActionBar by creating a NO ActionBar Style in the Style.xml and setting the class's style to that.
In Style.xml
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Then In the Manifest set the theme for the class to this NoActionBar Style.
In AndroidManifest.xml
<activity
android:name=".MainActivity"
android:theme="#style/AppTheme.NoActionBar" />
Method 2
Simply add a default NoActionBar Style in Manifest
<activity android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar" />
Method 3
You can do it programmatically
Java
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
Kotlin
supportActionBar?.hide()
try
private void hide() {
// Hide UI first
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.hide();
}
i am new in Android development in java
my activity_main.xml file is look like this
But when i run this application in my pixel 3 phone than it's look's like
why this design are different ?
As seen in background, you ignore missing constraints. When working with ConstraintLayout you must provide at least one horizontal and one vertical constraint, otherwise views could jump, and I believe IDE gave u that error.
check your style file.
By default is with Dialog.
u can change it with No Dialog
Sorry i mean
the line
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
u can change the theme with no actionbar
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
there are many variants
if you want to have a full screen theme like Design(activity_main.xml):
solution 1: go into the manifest and use a full screen theme.
<activity
.
.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
solution 2:
Just add the following attribute to your current theme:
<item name="android:windowFullscreen">true</item>
for example :
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/orange</item>
<item name="colorPrimaryDark">#android:color/holo_orange_dark</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
solution 3 :
public class MainActivity extends AppCompatActivity {
#Override
public 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.main);
}
}
and for manage your buttons, read Dorian's answer to Design and actual app look same.
I have an activity with a dialog theme (Theme.AppCompat.Light.Dialog.Alert)
Inside this activity i created a ViewPager because i want one image slider.
But my ViewPager create something like an actionBar before the slider. How can i remove it?
If my activity had an normal theme (not like a dialog) i could hide it doing the following code:
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
But it doesn't work in a dialog theme....
EDIT
My problem:
I want remove the "PageViewExample" =/
i already tried the following string and nothing happens
requestWindowFeature(Window.FEATURE_NO_TITLE);
I just added some style to my theme.
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
I don't want to use the Sherlock action bar, but I do want to change the text color. I know how to change the actual text
ActionBar actionBar = getActionBar();
actionBar.setTitle("Whatever");
but I don't know how to change the color. I have also tried this:
<style name="ActionBar.Solid.Example" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_background_textured_example</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_example</item>
<item name="android:backgroundSplit">#drawable/ab_background_textured_example</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example</item>
<item name="android:textColor">#android:color/white</item>
</style>
From the "Android Holo Colors Generator", I added the line
<item name="android:textColor">#android:color/white</item>
but it didn't do anything.
Any help? Thanks!
Seems you must use
<item name="android:actionBarStyle">#style/Widget.MyApp.ActionBar</item>
Here is solved the similiar problem:
Action Bar Sherlock 4 title text colour - where am I going wrong?
I need to have the action bar hidden on application start. Then, after some user action, it has to show up again overlaying the content. Currently I turn it off in a custom style by setting <item name="android:windowActionBar">false</item>, and then call
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
getActionBar().hide();
in onCreate() of the activity.
That seems a little awkward though. Can I do all of it in xml configs?
I don't know about the hiding part, but you cna style the ActionBar as an overlay in your apps theme like this:
<style name="AppTheme" parent="#style/Theme.AppCompat">
<item name="android:windowNoTitle">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowActionBarOverlay">true</item>
</style>