Should toolbar's title change according to activity? - java

So, really silly question but should toolbar title change from activity to activity? I searched for it on the Material Design Guidelines but couldn't find it. As of now it just display the app’s name on the toolbar on all activities. I am wondering if it follows material design guidelines/best practices on Android to keep it or change it according to the activity being presented.
So, should it be like the same on all activities or is it advisable/recommended to change it like: Going from home screen to Chats activity it would be App_name -> Chats instead of App_name -> App_name?
If so, what is the best way to change the title according to each activity?

Should toolbar's title change according to activity?
That depends on you not Material Design. Do you want to tell users clearly that this is another part of your app? Do you want to promote brand? Does this activity need a title at all?
what is the best way to change the title according to each activity?
I'll assume this is a technical question.
You have to mind two usages:
The activity title (or label) that's advertised to the operating system. This is used in launcher icons and in Recent Apps screen. It's also the default title text shown in the app (if applicable, read further).
The title text shown in the app.
How to assign activity title
Case 1) You have title in the manifest
If you defined the activity title in the manifest like so
<activity android:label="Some title"/>
if you don't specify it it inherits the app name.
Case 2) Assign title at run time
You can set the activity title manually at run time like so
activity.setTitle("Some title");
activity.setTitle(R.string.some_title);
Note: Inside an activity it's just setTitle(...).
Show title on screen
The default title will get automatically shown in Action Bar when you
setSupportActionBar(toolbar)
or if you manage a Toolbar yourself, you can set the title manually
toolbar.setTitle(activity.getTitle());
If you change the activity title later you'll also have to repeat the call on toolbar, there's nothing automatic about the process. I'm not sure about the Action Bar case.
You can also set the Toolbar title to anything else you like
toolbar.setTitle("Some title");
toolbar.setTitle(R.string.some_title);

Related

How to Show Custom View (FAB) On All Screen in Android

I want to show my custom floating button on all screen in my app without putting it in each activity.
Do we have some Global Activity like put a code once will show the Custom View all screen and hide/remove when app killed
I tried lot of things like Screen Overlay display over all apps
Please check code here - How to display custom view on all screen in android from my library
I've never tried to do it the Java/Kotlin way. But have you considered using Fragments?
You can declare xml layout and code for one Activity with a FrameLayout container and an FAB. The container holds all your screens and they switch between each other in the container. The FAB is on top and therefore will be displayed no matter the screen.
The Activity has a reference to any screen that might be displayed in it, so the FAB can behave accordingly.
Not sure if this helps. Perhaps if I see some pictures, I could suggest better.
Related Read:
Creating a fragment: here
Fragment Transactions: here

How should I structure bottom navigation in Android coming from iOS background?

Some background:
Coming from an iOS background, using UITabbarController is very common and straight forward. Each Tab in the tab controller will change the current view to another UIViewController, and each of these UIViewControllers can have its own NavigationController (which kind of acts as a back stack). So whenever I switch tab, I would resume to the state where I left off.
Now I want to implement the same thing in Android, but it seems like the use of ViewController is different in Android. After digging around, I read that instead of using Activity like UIViewController, I should use Activity to act more like NavigationController, and use Fragments (which is deprecated)
to act as UIViewController instead.
However my question is:
Should I be implementing multiple Activities for Bottom Navigation? When I click on each item in the Bottom Navigation should I use an Intent to change Activity? Because from my understanding, using Intent to change Activity will add the new Activity to an Activity back stack, which would prevent me from switching back to whichever Activity I want. If someone could, Please tell me what is the "right" way (if there is one) to structure Bottom Navigation. Thank you all in advance.
You can use fragments as UIs, And Use a BottomNavigationView in your activity or you can use some libraries.
Here is a library for better customization: https://github.com/ittianyu/BottomNavigationViewEx
Native Method:
https://medium.com/#hitherejoe/exploring-the-android-design-support-library-bottom-navigation-drawer-548de699e8e0
In Android you should use Viewpager, tablayout and Fragments. Just search for its tutorials. there are lots of them on internet

View's contentDescription does not work correctly with TextToSpeech

I work with TextToSpeech and adding "android:contentDescription="#string/custom_button" for ImageButton in xml, reads the value from "#string/custom_button" and adds another "button" in speech.
EG:
"#string/custom_button" = "Custom Button" mapped for mentiond ImageButton, is read as "Custom Button button". There is no text in this button. Id is much different.
How to get rid ot this last "button". It refers to all views read by TextToSpeech.
From my work/research with accessibility, Android automatically adds "button' to the end of talk back for buttons. I could not find any documentation breaking now accessibility to the coding level, but from what i gather they probably add this in the case the developer forgets to indicate in the content description that the the user has clicked a button. There is nothing you can do to remove android's addition of the word button. What you can do is remove it from you custom description so that is only says "Custom". Hope this helps.

How to make one part of activity always visible on Android?

I've created ListActivity and other Activities, which I would like to be displayed when I click item from ListActivity. My problem is that I don't know how to do it in the same window, so that the ListActivity will stay always visible, while other part of the window will change based on the pressed element.
You would have to have only one activity, such as by converting "other Activities" into fragments that are displayed by the ListActivity.
Instead of using Activities, I would implement your functionality in Fragments. They allow for increased modularity of an application, and will allow for the functionality that you desire, at runtime they can be "swapped out" with inside your ListActivity.
Reference to a thorough overview of Fragments on the Android Developer website: http://developer.android.com/guide/components/fragments.html

Android Pre-Load Splash Screen

Hopefully this isn't a dumb question, but when I initially click on my app, a kind of splash screen first appears for a few seconds with just a title bar indicating the name of the app and nothing else - then the app loads as expected. Is there any way to remove this screen?
The system looks into your AndroidManifest.xml to find out what is the theme of the main Activity. If you don't specify it manually, it assumes the application theme, if you don't specify application theme then the default theme is used. The system then creates the "splash screen" solely acoording to the theme.
So if you want to remove it, create a theme that has a transparent background and no ActionBar. And in onCreate() you probably want to change the theme again (or just change the background and show the ActionBar).
But it's better to have some visible "splash screen". Otherwise if you click on the icon, you won't see nothing for 1 - 2 seconds, which is quite weird, almost no app does this.
Initializing more resources on
onCreate()
may take some time. Try not to overload onCreate() method of Activity.
Try not to deep down more than 30 levels inside the xml layout file. which can also take up some time to initialize .
setContentView(R.layout.main)

Categories