How to save view in action on Android

I am working on an Android application, and I would like to support the top bar in most of my activities, according to the Twitter and Facebook applications. How it's done? I would like to keep it there always, as it will provide a functional core for the entire application.

+4
source share
5 answers

Break the title bar into a separate layout and use the include xml tag. I do this in several of my applications. Each of your actions can be inherited from the Base action, which contains events for the included layout, for example, if there are buttons in the title bar.

An example of pseudocode below.

title.xml

<LinearLayout> <TextView text="Some text"/><Button text="Some Button" onCLick="buttonClick"/> </LinearLayout> 

activity layouts for each layout

 <RelativeLayout> <include layout="@layout/title" /> </RelativeLayout> 

Baseactivity

 public class BaseActivity extends Activity { public void buttonClick(View v) { // do something interesting. } } public class OtherActivity extends BaseActivity {} 
+10
source

I have some problems with syntax highlighting, but I tried to give an example of how to perform a similar task:

http://illusionsandroid.blogspot.com/2011/02/android-custom-tab-bar.html

+2
source

GreenDroid has an excellent toolbar, which, it seemed to me, is very useful, extensible and easy to use (and its source code for downloading).

https://github.com/cyrilmottier/GreenDroid

+1
source

I think that it is best to define a custom view and reuse it where necessary. Although I do not think that you have technically the same instance through actions, you can create the illusion by updating it when necessary. (Perhaps in the onResume () method for each activity.) To save data, you can use SharedPreferences , which are stored in different actions in the application and even between instances of a specific application.

0
source

Source: https://habr.com/ru/post/1339842/


All Articles