How to change app subtitle in the head section - java

A screenshot of my activity preview
I'm new to android studio and have been following various tutorials online. Cant find the answer to this problem. if i change the app_name in the strings.xml, the name on the picture posted above also changes and if i generate the apk it also acts as the app name. I tried to add another string on the strings.xml but nothing changes. Is there a way to edit the title above without changing the final app name
strings.xml code
<resources>
<string name="app_name">Hello world</string>

That's because the same String is being used in both the layout where your image shows, and in your Manifest file.
You might recognize this code inside your AndroidManifest.xml file:
<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>
</application>
Note the part that says android:label="#string/app_name". That's the String that your app will show as the app name.
So if you want to use two different names, one for the app name and one for inside your layout, simply create two different Strings and assign one to the AndroidManifest.xml and the other to whichever layout you're image shows.

Use the app_name in the intent-filter of the launcher activity. and use a different string for android:label of your activity. Manifest would look like something this -
<activity
android:name=".MainActivity"
android:label="#string/title_main_activity"
android:icon="#drawable/icon">
<intent-filter android:label="#string/app_name">
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And create <string name="title_main_activity">Hello Main Activity</string>

Related

Android Deeplink opens application twice

i used webview to create app and implemented deep linking like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ariagp.myapplication">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<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>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="https" android:host="mysitename.com" />
</intent-filter>
</activity>
</application>
</manifest>
it will asking my for open with my application before open the links, but the problem is:
two applications will open in the phone task manager (the application does not open in the previous application which is running):
what is the solution?
Add android:launchMode="singleTask" in declared activity in AndroidManifest.xml.
And then, in your activity, you should override onNewIntent() method and you will get arguments there.
Ok, so you don't actually have a problem here.
This is just how deep links work. If you open one in a certain app, the deep link will open your app but in the same window the deep link was originally in.
Your app will have two instances in a way.
You could go to you web brower app and click share and any app that pops up. They all open in the web browsing app window. So there is nothing to worry about. I had the same problem myself before I realised that it is just how things work.
Some apps are just verified to open other apps if they implement the browsability.
Add android:launchMode="singleTask" in declared activity in AndroidManifest.xml.
And then, in your activity, you should override onNewIntent() method and call mNavController.handleDeepLink(intent) there.
It is worth mentioning that you are now able to get your arguments using, private val args: XFragmentArgs by navArgs()in your fragment.

Application label did not work

I have android:label="Name app" in <application
and android:label="Activity name" in <activity
(all in androidmanifest.xml)
and if i install this app on real device, this app have name "Activity name"
why ? How can i change app name ?
edit1
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher2"
android:label="Dog"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name=".FirstActivity"
android:label="Cat"
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".secondActivity">
</activity>
</application>
and app still have name Cat in my phone
in phone menu, under icon this app
That is not the label of the application. That is the label of the specific activity that has the MAIN/LAUNCHER <intent-filter> in your manifest. If you want to change this label, change the android:label on that <activity> element.
The android:label on <application> serves as the default label (for <activity> elements that lack one) and is used in places like the Settings app.

Creating a new Activity, makes a whole new application?

Im new to android, and when i read "Create New Activity" i was under the impression it creates a new "Window/Layout/Screen".
When i start making my own application i see
Main.java
is one application and
SecondActivity.java
is another app in my Emulators menu?
Why is that and how can i go about making one app with multiple windows as apposed to multiple applications essentially?
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ryan.bidorbuyapp" >
<application
android:allowBackup="true"
android:icon="#mipmap/bidorbuy_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:theme="#style/FullscreenTheme" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchResults"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/title_activity_search_results"
android:parentActivityName=".FullscreenActivity"
android:theme="#style/FullscreenTheme" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.ryan.bidorbuyapp.FullscreenActivity" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
thanks
Look at your AndroidManifest.xml there is the problem. Your activities have Launcher between it's tags. Only one activity must have LAUNCHER tag
Only one activity must have
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
You should understand what is an Activity before starting to developing an android application. You can think an activity as a page in web. There can be one or more and every activity includes their own contents.
When you create a new activity in your project, you should navigate by doing some operations in another activity. Intent helps you at this point to navigate one activity to the another.
Your problem is that, you should check your AndroidManifest.xml file. Please check the declaration of intent here. I think you will solve it after making a search about Intent.

Trying to have main menu and submenu classes

So my original problem was that in my manifest my menu wasent loading ie
<activity
android:name=".MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.th3ramr0d.learnar670_1.MAINMENU" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
This was fixed by loading it at startup ie
<activity
android:name=".MainMenu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
So now my main menu works. However, the buttons inside MainMenu.xml will take you to another .xml file with more buttons. So now I have the same problem. I created another class called SubMenuChapter3 and put it in the manifest as such.
<activity
android:name=".SubMenuChapter3"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.th3ramr0d.learnar670_1.SUBMENUCHAPTER3" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Now this doesnt work I am assuming for the same reason as before with mainmenu. Doesnt crash or give me errors. It just wont open the submenuchapter3 class. I forced the submenuchapter3 class to open by putting
startActivity(new Intent("com.th3ramr0d.learnar670_1.SUBMENUCHAPTER3"));
directly into the MainMenu class outside of an onclick just to see if it was working. When I do that it opens the chapter_3.xml like it is supposed to and the button works. Thanks for the help.
You misunderstood <intent-filter> tag and the way you start activities.
Also maintain proper terminology - Menu and Activity are completely different things.
Everything you need to know about Activities can be found here: Activities | Android Developers
Example:
This entry in AndroidManifest.xml says "show the MainMenu Activity as icon in the launcher":
<activity
android:name=".MainMenu"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
EDIT: This allows Android to start MainActivity. It will also show in the installed app list.
The following Activity will not be displayed in launcher but can be opened from the app:
<activity android:name=".SubMenuChapter3"/>
EDIT: This allows Android to start SubMenuChapter3. It won't show in the installed app list.
These lines say "open the SubMenuChapter3 Activity":
Intent i = new Intent(this, SubMenuChapter3.class);
startActivity(i);
EDIT: You call this code from inside the onClick method inside MainMenu. It will launch SubMenuChapter3.

Android : Change App Label programmatically

How can I change application label to change app name shown from java code in android?
I'm refering to:
<application android:icon="#drawable/icon" android:label="#string/app_name">
in the Android Manifest
Is there any way to update values in strings.xml file?
in the activity, i tried
this.setTitle("your text");
and it worked. I hope it's a common solution
It's not possible by the moment. It is a fixed string in the AndroidManifest.xml file which cannot be changed at runtime.
Using <activity-alias> you can change App icon and name to few predefined by you.
Create such config in Mannifest.xml
<activity android:name="package.name.MainActivity"
android:screenOrientation="portrait"
android:label="#string/app_name"
android:theme="#style/CustomTheme"
android:launchMode="singleTask">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity-alias android:label="#string/app_name_default"
android:icon="#drawable/icon_default"
android:name=".MainActivity-Default"
android:enabled="true"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="#string/app_name_flavor_one"
android:icon="#drawable/icon_flavor_one"
android:name=".MainActivity-Flavor-One"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
Now you can switch between those two aliases, therefore we will change app icon or/and name.
To switch from Default to Flavor-One use this code.
getPackageManager().setComponentEnabledSetting(
new ComponentName("package.name", "package.name.MainActivity-Flavor-One"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
getPackageManager().setComponentEnabledSetting(
new ComponentName("package.name", "package.name.MainActivity-Default"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
Keep in mind that you have to track that only one alias will be enabled at a time
In Launcher Activity,Before setContentView() write this,
setTitle("Your Title");
I don't know how it's possible, But it's surely works.
Yes, Its possible, In this question everyone mentioned like
this.setTitle("your text");
this will change only your activity name not app logo here I show you how to change the app logo and appname dynamicly
First add your dynamic app icons in the mipmap folder , after that add the below code in your AndroidManifest.xml file
Add <activity-alias> for your app icon
<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" />
<!-- Disable the original activity app icon in launcher -->
<!-- <category android:name="android.intent.category.LAUNCHER" /> -->
</intent-filter>
</activity>
<activity-alias android:label="Anand"
android:icon="#mipmap/ic_launcher"
android:roundIcon="#mipmap/ic_launcher_round"
android:name=".MainActivityAlias1"
android:enabled="true"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:label="Anand 1"
android:icon="#mipmap/ic_launcher2"
android:roundIcon="#mipmap/ic_launcher2_round"
android:name=".MainActivityAlias2"
android:enabled="false"
android:targetActivity=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
</application>
After doing these methods on your activity, just do below things on button click
import android.content.ComponentName
import android.content.pm.PackageManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button1.setOnClickListener{
packageManager?.setComponentEnabledSetting(
ComponentName(applicationContext.packageName, applicationContext.packageName + ".MainActivityAlias1"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP
)
packageManager?.setComponentEnabledSetting(
ComponentName(applicationContext.packageName, applicationContext.packageName + ".MainActivityAlias2"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
)
}
button2.setOnClickListener{
packageManager?.setComponentEnabledSetting(
ComponentName(applicationContext.packageName, applicationContext.packageName + ".MainActivityAlias1"),
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP
)
packageManager?.setComponentEnabledSetting(
ComponentName(applicationContext.packageName, applicationContext.packageName + ".MainActivityAlias2"),
PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP
)
}
}
}
for more details refer this github project
Application's android:label is a fixed resource referrer.
But the string under this referrer could have multiple values, depending on configuration qualifier names (values-en, -large, -land, etc.), according to
Providing Alternative Resources.
To anyone interested: Android How to change the application title
But it's not clear if it changes the "application label" (that is, the name of the icon in the application list) or only the window title.
If you are extending the firmware, you can actually accomplish this by changing IconCache.java file and make it show a string with some internal value of the phone.
For example if you want the SIM Toolkit to show the name of the carrier, you can do that this way.
But for regular apps, as it's been said, it's currently not posible.
As Mister Smith said, it is not possible,
but you could use multiple ActivityAlias, which can be enabled/disabled dynamically and point to the same targetActivity. Therefore create your chooser for the app name - let the user select one and enable the ActivityAlias via the packageManager:
ComponentName componentName = new ComponentName(context, context.getPackageName() + "." + aliasName);
context.getPackageManager().setComponentEnabledSetting(componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP);
To hide the old alias, use the same code with the flag : COMPONENT_ENABLED_STATE_DISABLED
You can also add the possibility to directly add a shortcut to the home launcher, after you enabled the alias. There are plenty ways described here on sow.

Categories

Resources