With Android 5, Google supports multiple activities in the recents screen for a single application.
I managed to implement multiple activities in the recents screen with this official doc.
How can I change the title of the activity? Switching to recents screen always shows my app name as title.
Activity.setTitle("title");
changes the title on the toolbar, but I want it to change in the recents screen, just like Google does in Google Chrome App.
I need to change the title programatically.
In your activity you can use new method:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.secondary_layout);
setTaskDescription(new ActivityManager.TaskDescription("Activity 2"));
}
setTaskDescription sets information about activity in recents task list. In this example only title.
Related
I have a problem with showing simple google.com in my WebView.
Tried this on few emulators and 2 phones, all the same, something is wrong with my code.
1. Issue
First screen shows normally google's asking user to accept their legal stuff (1st image).
After accepting it moves to google's main page. But only lower part (Country, settings, adds, about etc.) is shown (2nd image). There is no Google logo, no search bar and buttons and no stuff from the upper display (like GMAIL, GRAPHICS, ACCOUNT and so on).
1ST SCREEN OF GOOGLE.COM
INCORRECTLY SHOWN GOOGLE PAGE
2. Code
I added permission in Manifest.
Trying to solve the issue I stackoverflowed below two lines and added to Manifest, but to no avail:
android:hardwareAccelerated="true"
android:usesCleartextTraffic="true"
**
3. My java code is below:**
(each of the settings I tried to comment out and then one by one uncomment, but still no result).
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setDomStorageEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setDomStorageEnabled(true);
webView.setWebViewClient(new WebViewClient());
webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
webView.loadUrl("http://www.google.com");
}
}
Could someone please check this is tell me what I've done wrong here?
Stupid thing, should not have done this late into the night.
The problem was only with layout, rest of the page was out of screen.
Needed only to match the WebView to constraints.
When I was browsing the slack application I found new feature I liked, which is the return of activity by dragging without pressing the back button as usual.
So is there a specific code to do that? I did a research on how to do that but I couldn't find any explanation for it, so how can I do that.
Here is a short video about the new feature
click here
Thanks to Coding in flow for that. Watch this tutorial for more explanation.
Follow these steps to do the job.
1- We will use a library to do that called Slidr, use the last version.
// swipe the Activity to close
implementation 'com.r0adkll:slidableactivity:2.1.0'
2- Add a new style in your styles.xml called SliderActivityTheme.
This theme will make the background for the activity when swipe it as transparent to show the content of the fragment...etc, "default background white"
<!--Theme for Slider Activity-->
<style name="AppTheme.SliderActivityTheme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
</style>
3- A- Add slide method to your class and called in OnCreate
// Make slider on the Activity
public void Slider () {
Slidr.attach(this);
}
B- Called in OnCreate
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_activity_name_here);
// slider the activity
Slider();
}
or just simply add this in your OnCreate directly
// slider the activity
Slidr.attach(this);
4- In your AndroidManifest.xml add the theme that we had to create.
android:theme="#style/AppTheme.SliderActivityTheme"
Make it like that
<activity
android:name=".Activity.ActivityImages.ImagesMorningActivity"
android:launchMode="singleTop"
android:theme="#style/AppTheme.SliderActivityTheme"/>
<activity
That's all, and enjoy with your new feature ;)
Working with Fragment? No problem, check the library page to know how to do that
I have a simple android app with WebView which opens the site main page. I need to save WebView state when the user presses "home" or "main menu" buttons. And then, when user opens app from the homescreen or main menu I need to load this saved state.
Everything works fine except the first launch (after installation of built apk file): if I open app from main menu the WebView restores just fine, but if I try to open it from homescreen it starts to reload. Is there any ways to fix that? Thanks in advance.
P.S. if I install app from Android Studio (not from built apk file) everything works as I expect, so I am confused.
These are methods where I save and restore WebView:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
if (savedInstanceState != null)
webView.restoreState(savedInstanceState);
else
webView.loadUrl(getString(R.string.URL));
}
protected void onSaveInstanceState(Bundle outState)
{
webView.saveState(outState);
super.onSaveInstanceState(outState);
}
How do I change Toolbar Titles in different bottom navigation activities, I currently have one displayed in all which is one my manifest
android:label="#string/home"
but since I have four activities on my bottom navigator how can I rename them all on the activities, I tried adding a toolbar it added below the original, home. Tried renaming manifest particular activities doesn't work. Thanks in advance.
I tried setting titles on the activities like this:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_collections);
setTitle(R.string.collections);
}
I want to have something like this, Image One Image two
You can use setTitle in your activity.
Problem Description and Question
I'm using tab activity with action bar. In the HOME tab I have GridView which contains some items, like it is shown in the image below (Hot Lines, Taxi, Restaurants etc)
Wen user click on the items in the grid view I want my application to take following actions:
Change icon of application to grid view item image on which I pressed.
Change the test near the icon
Add standard back button near icon, which will go back to grid view screen.
Change the tab fragment to the one which I specify.
Like it is shown in the image below:
As I never deal with this kind of problems can you please give me example or share some link with me of how I can do this? and can I do this at all?
This might help:
Android studio - is possible to add tabs pointing to fragments from designer?
It is not exactly what you want, but a good start. If you are willing to put a bit of work in it, you should be able to get what you want. If you have a basic Frame to work with and more specific problems with this matter I will gladly help you out ^^
John
The first link you can check is THIS.
And you should read more about ActionBar.
The last thing is it's better if you google it first and try to write a code and when you got stuck somewhere share your code with us and ask for help.
You have to use actionbarsherlock library for it.
use android.support.v4.app.FragmentTabHost and TabWidget in the xml as shown below :
<android.support.v4.app.FragmentTabHost
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
style="#style/yourstyle"/>
<FrameLayout
android:id="#+id/realtabcontent"
style="#style/realtabFrameContentStyle" />
<TabWidget
android:id="#android:id/tabs"
style="#style/yourtabstyle" />
</android.support.v4.app.FragmentTabHost>
Use SherlockFragmentActivity for showing the tabs.
In the activities code use following code (preferably in a function) to set the ctionbar icon and text :
activity.getSupportActionBar().setDisplayShowCustomEnabled(true);
activity.getSupportActionBar().setCustomView(R.layout.your_action_barlayout);
((TextView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.action_bar_title))).setText("your title");
ImageView homeButton = ((ImageView) (activity.getSupportActionBar().getCustomView().findViewById(R.id.your_icon)));
homeButton.setVisibility(View.VISIBLE);
homeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(context, YourHOmeActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
activity.startActivity(intent);
activity.finish();
}
});
ActionBar mActionBar = activity.getSupportActionBar();
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
mActionBar.show();
then call this function with your icon and your text in your fragments onResume() method.