I'm building an Android application which contains a fixed header with the application title in it. Right now, when the application changes activities, the header will slide out and slide in as well because both activity's have the same header. I really like this header to stay fixed at all times, even when switching activities.
I think this could easily be done by using a viewswitcher/viewflipper on the lay-out below the header and switch views only on that perticular part of the application. That would create my desired effect. The problem with this is, that every single screen I have in my application, would use the same java file. As I have around 12/13 different screens, all containing buttons textviews, listviews etc, that would create very messy code. I'd therefore prefer to use java files for each 'screen' but then I'd have to stick with different activity's and I can't keep the header on top during transistioning of activity's.
Is there a solution to actually keep a fixed header (and be able to animate the view/lay-out below) while using different java files for every application screen?
Work with Fragments, a FragmentStatePagerAdapter and a ViewPager. You could create a layout where you have the fixed header - and below that you have your ViewPager containing the different Fragments, each containing their own logic.
It's quite a change working with Fragments instead of only Activities, however I've found them very useful. For a starting point, check this link.
To not allow the user to swipe, but still being able to switch the viewpager item programatically, check out this tutorial and do your swiping using the setCurrentItem method.
Related
my problem is that:
I want to make a login service in my application and depending on which user logs in, go to a different NavDrawer activity. In Android Studio when you create the NavDrawer activity that comes by default, it generates one perfectly. But when I want to generate a different one, having the same name doesn't create anything.
The only way I have found is by refactoring everything generated by the Android Studio wizard and changing all the names of the layouts.
I would like to know if there is an easier way to create another NavDrawer without having to refactor so much and without so many errors.
Thank you!
NavDrawers Generated
Conceptual Scheme
Its Solved, you only need to make an instance of one of these nav drawers and then extend that to another one.
I'm working on an Android application with an activity dedicated to a webview. I also have a chat section of the app that autolinks web links in the messages. I've created a onItemClick listener on the chat messages to start the webview activity. This listener works when I click the whole chat bubble, but I noticed that if I only click the highlighted link in the message, the listener isn't called and instead my default browser is loaded up.
I put a log message in front of every instance of an intent with ACTION_VIEW, thinking that some other part of my app may be launching the browser, but it doesn't seem like this is the case.
I'm wondering if android has any default methods that catch autolink urls and starts the browser that I could override. Otherwise, I was thinking that I could turn off autolink and imitate the appearance of links with the blue text and the underline, but this seems like a poor solution.
Thanks ahead for any tips on how Android works!
I encountered this situation too, where I have autolink set up in TextViews to automatically handle URLs in TextViews. However, the default behavior is to open the web page in an external browser, so how do we make it open in a webview activity (for example)?
Beneath the hood, this is handled for TextView by LinkMovementMethod. However, the behavior is difficult to customize. There is a 3rd party enhancement over LinkMovementMethod, known as BetterLinkMovementMethod, described in more detail in this blog post. With just a few lines of code changes, the TextView autolinks can be made to open in your webview activity (and clearly, all kinds of other behaviors can be customized as desired).
I am working on a JavaFX project and I am creating an UI based on Google's Material Design patterns. I use a library that includes a lot of components based on this design, named JFoenix.
Basically I have a JFXTabPane with different tabs, and in one of them I want to make something to Search on a TreeTableView, and I got as idea to replace the TabPane's header (where the tabs display) with the Search bar.
I've been looking this up on Google and haven't found anything. Any ideas?
I have multiple classes with different layouts which I call them Widgets in my app (this is a whole different thing from so called "Android Widgets"). I want to put instances of these classes beside each other in an activity called Dashboard. So users can change the place and settings of these widgets inside the dashboard and etc... .
I tried to use DragListView library, but the problem is each list mush have one layout AFAIK.
Any suggestions?
Just starting out on android developing. To start off, I'm building an app which is gonna function like a gallery+image viewer, with the added functionality of quickly and swiftly moving pictures into subfolders, for easy sorting of lots of pictures.
So far I have 2 activites - a full screen image view, and a full screen thumbnail grid (for multiselect purposes).
Now as I'm new at this, I was wondering if this dual-activity was a wise decision. Would it be better to simply switch between content views than to power up an entirely different activity when switching from image view to grid view (and vice versa).
What I'm looking for are of course the obvious pros and cons - performance, ease and usability. But also if there are more fundamental "pattern"/best practice reasons for one or the other.
Thanks
I think your dual activity approach is sensible. Generally speaking the Android Activity/View APIs are structured around having a single fixed View per Activity. Although you can manipulate Views within your Activity's layout, I'd suggest this should be restricted to hiding/showing/moving Views rather than replacing the layout wholesale.
What you probably should consider is the newer Fragments API. This can almost be though of as "activities within activities". A Fragment essentially allows you to wrap up an element of a UI (layout and behaviour) in a reusable component. So in your specific example, the two distinct UIs could be Fragments within a single activity.
This has a couple of benefits such as being able to reuse your UIs in other activities and you can do funky transition animations.
dual activity should work, as you won't be bothered by implementing the back button action.
Activities were made exactly for this purpose. If you prefer, you can have your whole application in a single activity with a custom layout engine (reload components, etc.) and that's what you want to do if you want a "portable" app (e.g. you develop an app with a common UI for various platforms, Andropid, Windows 7, iOS, etc.), but if you want to go Android only, the preferred way is to use the provided APIs, and not to reinvent the wheel. It works fine, and will give users a comforting sense of consistency in their experience (it will look and feel like other Android apps).
The current project I'm working on (a game) already has 10 different activities, and I'm planning more...