- How to Change the Color of Status Bar in an Android App?
- Method 1: Creating a New Theme
- Method 2: Using setStatusBarColor Method
- Gradient Toolbar & Statusbar in Android
- How to make Gradient Toolbar and Status bar in Android
- How to Create Custom AppBar/ActionBar/ToolBar in Android Studio | Java
- Gradle dependency
- Set the styles
- Design our AppBar/ActionBar/ToolBar
- Как удалить строку заголовка в студии Android?
How to Change the Color of Status Bar in an Android App?
A Status Bar in Android is an eye-catching part of the screen, all of the notification indication, battery life, time, connection strength, and plenty of things shows here. An Android user may look at a status bar multiple times while using an Android application. It is a very essential part of the design that the color of the status bar should follow the color combination of the layout. You can look out to many android apps on your phone and can see how they changed it according to its primary colors. There can be multiple ways for changing the status bar color but we are going to tell you about the best hand-picked two methods which you can use either in Java or Kotlin.
Method 1: Creating a New Theme
You can follow this method in apps that are built with Kotlin or Java. It will work in both.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Step 1: Open Android Studio and start a new project by selecting an empty activity. Give it a name of your choice, then select your language and API level. At last click on finish.
Step 2: Find an XML file called styles.xml by navigating res/values/styles.xml.
Step 3: Find another XML file by navigating res/values/colors.xml, and also add that color here which you want to change for the status bar.
Step 4: Now in the style.xml file, add the below code just before the tag and change the colors of it as your choice. ColorPrimaryDark is always going to be responsible for your status bar color.
You can do the same with android:statusBarColor but it will work only in above API Level 21. ColorPrimaryDark for the status bar will also not support in API Level 19. By default in most of the API Levels, ColorPrimaryDark will be the default color for statusBarColor, So it is good to go with changing ColorPrimaryDark.
Tip: You can create multiple themes and you can use them in any activity. In any theme, There is a set of colors that needs to be defined, you can also create new colors in the colors.xml file in the same directory and use it on the styles.xml file.
Step 6: Now go to the manifest/AndroidManifest.xml and here search the activity for which you want to apply that theme or change the color of the status bar. and add an attribute android:theme=”@style/DemoTheme”.
That’s done! Check your application by running it on an emulator or a physical device.
Method 2: Using setStatusBarColor Method
This method can be only used in the above API Level 21. Officially status bar color is not supporting below API Level 21. Although, Here we added an if condition, because in case if you haven’t selected above or equal to API 21 then it will check the android API Version, and then it will execute the code. It will not change the color of the status bar is below API Level 21 but the rest code will work well.
Step 1: After opening the android studio and creating a new project with an empty activity.
Step 2: Navigate to res/values/colors.xml, and add a color that you want to change for the status bar.
Step 3: In your MainActivity, add this code in your onCreate method. Don’t forget to replace your desired color with colorName.
Источник
Gradient Toolbar & Statusbar in Android
Gradients are a trend in mobile app design that brings life to the app UI. Creating a gradient toolbar is a relatively simple task in Android, you achieve it by simply adding a gradient background to the toolbar, but this doesn’t cover the status bar, thus not creating the desired effect.
Toolbar and status bar are separate entities in Android. Thus there is no straightforward way to have a single gradient from the top of the screen to the bottom edge of our toolbar. But there are hacks to achieve this. Let’s see how we can do it.
The first step is to create a gradient drawable. Create an XML file in your drawable folder named gradient_bg.xml.
For choosing awesome gradient colors for your app, I recommend CoolHue and uiGradients.
Now, before we design our custom toolbar, we need to make sure that Android doesn’t attach a toolbar automatically. Open your styles [res/values/styles.xml file].
Override your app style. The first two styles here, remove the default action bar of android from your app so that you can add your custom-designed action bar. The next two lines ensure that your app window covers the status bar on the top, but leaves the soft button bar on the bottom.
Okay! Now it’s time to create our custom toolbar. 24dp is the default height of the status bar. And the default height of status bar + toolbar is 80dp. So we give our RelativeLayout a height of 80dp to accommodate both, and we keep a top margin of 24dp because in the next steps we are about to push the parent container out of its default area into the entire screen area that includes the status bar.
In your activity layout, add the following code at the top of the root layout.
And in your activity’s onCreate method, add the following:
That’s it! Run the app, you should see a smooth gradient effect. You can play with the gradient colors and the angle.
Источник
How to make Gradient Toolbar and Status bar in Android
Android and Web Developer
Hello there, Today we are going to learn how we can make an amazing custom toolbar with gradient effect and also apply the gradient to the status bar like below
First, let’s create a new project or open your existing one.
To make gradient to status bar and toolbar we need to edit our styles.xml file to make it no action bar theme and apply full-screen so that we can add our custom status bar.
See below snippet of styles.xml and edit your like this.
Open res folder then open values folder and select style.xml.
First, we need to change the parent attribute and replace the value with by doing this default action bar will remove.
Now we add some property in the styles.xml
This will give us the ability to add a custom status bar.
For the custom toolbar, we need to make a custom layout file.
To do that we create a new layout file by right click on the layout folder and then click on new and then click on the layout resource folder.
We will name this file as .
In this file, we will add a toolbar widget in the linear layout and set the height to action bar size and set id as toolbar. Also, we set the height of linear layout to 80sp and set gravity to bottom because the height of the default status bar is 24sp and the action bar size is 80sp — 24sp = 56sp.
Our file will look like this below.
To add the gradient to our toolbar and status bar we need to create gradient drawable so let’s create a drawable file.
Right-click on the drawable folder then click on new and then drawable resource file and we name this file as .
Now copy below code and paste it in your file.
In the above code, we are creating a new gradient background for our toolbar.
To set this background to toolbar we need to open our custom_toolbar.xml file and add background attribute to the linear layout.
Now we have completed our custom toolbar part now its time to apply this toolbar on our activity.
To do this open your activity xml file and include your custom_toolbar.xml file like this.
After including the file we need to set the toolbar to action bar in your activity java file.
Open your activity java file and get toolbar by using findViewById and pass the toolbar id we set in custom_toolbar.xml file and call the setSupportActionBar method and pass our toolbar.
If you run your app you will see the gradient has applied successfully but the color of title in the toolbar is in black color which makes our toolbar look ugly. To make it look amazing we are adding white color to the toolbar title by calling method setTitleTextColor of toolbar widget and pass the static variable.
Now run your app and your beautiful and good looking custom toolbar will show up.
If you learn something new then share this article with your friends and mates. Thank You and have a nice day.
Источник
How to Create Custom AppBar/ActionBar/ToolBar in Android Studio | Java
Today in this tutorial, we’re going to see how to create a custom AppBar/ActionBar/ToolBar in android.
I also already created a tutorial on this topic, but here I will demonstrate it with different examples.
Gradle dependency
for circle image view:
Set the styles
now go to your styles.xml file and set the theme to NoAction Bar so that we can create our own toolbar.
Design our AppBar/ActionBar/ToolBar
now go to your main XML file and create a ToolBar and set the width and height, make sure min-height should be actionBar size.
this will give you just a toolbar without any field. Look at the below image.
for the logo, we’re using a circular image view. Already add the dependency. Put it inside the toolbar and do the adjustment.
here we set our title to null, so in the main java file assign our toolbar and do the below change
the result will be:
we can also set the logo by using app:logo=”your logo here” in your toolbar
the result will be:
for the menu, create a menu android resource folder and create a menu resource file ( /res/menu/custom_menu.xml)
import that menu in our main java file by using these code of lines
for adding a title simply add a textView inside the toolbar.
Источник
Как удалить строку заголовка в студии Android?
В моем приложении эта строка заголовка находится вверху, там, где должно быть дополнительное меню, но мне не нужны настройки, и у меня только один экран. Когда я меняю тему, как описано во многих других вопросах, я получаю старую тему 2.2. Я хочу иметь современную тему только без панели наверху.
Перейдите в styles.xml и измените его .DarkActionBar на .NoActionBar
если цвета не имеют отношения к вашему приложению, вы можете выбрать
В файле манифеста Изменить:
работает onCreate() при setContentView() вызове перед .
иначе он выйдет из строя
В файле styles.xml измените DarkActionBar на NoActionBar
Это работает для меня
В файле манифеста измените на это:
Это работало для меня при values/styles.xml добавлении элементов:
Перейдите в Project -> app -> main -> res -> values -> styles.xml
Измените эту строку, если хотите удалить ее для каждого просмотра
если вы хотите сделать это только для одного представления, вы можете изменить его в своих данных манифеста. Заходим в Android -> манифесты -> AndroidManifest.xml. сделать следующее:
- Найдите представление, в котором вы хотите получить изменения этого типа
- Добавить android:theme=»»@style/Theme.AppCompat.NoActionBar»
вы можете изменить name = «———«
найти android: theme = «@ style / AppTheme» измененный на android: theme = «@ style / no_title»
нажмите выбрать тему в строке меню (зеленый цвет рядом с MainActivity)
- нажмите тема проекта
- щелкните no_title (справа от вас)
- нажмите ОК
Источник