layout element defined globally
I'm trying to add a "You are offline" element to the bottom of each layout in my Android app. I would like to define it globally, not to paste the same element to each xml layout file.
I could probably create some ParentActivity and append it programmatically, but is it a good solution?
What is the best way?
Thanks.
java

add a comment |
I'm trying to add a "You are offline" element to the bottom of each layout in my Android app. I would like to define it globally, not to paste the same element to each xml layout file.
I could probably create some ParentActivity and append it programmatically, but is it a good solution?
What is the best way?
Thanks.
java

1
You can do that stuff inside a baseactivity with a specific layout you needed. From that layout you can create fragments and make your other ui logic inside them.
– denizt
Nov 21 '18 at 10:27
add a comment |
I'm trying to add a "You are offline" element to the bottom of each layout in my Android app. I would like to define it globally, not to paste the same element to each xml layout file.
I could probably create some ParentActivity and append it programmatically, but is it a good solution?
What is the best way?
Thanks.
java

I'm trying to add a "You are offline" element to the bottom of each layout in my Android app. I would like to define it globally, not to paste the same element to each xml layout file.
I could probably create some ParentActivity and append it programmatically, but is it a good solution?
What is the best way?
Thanks.
java

java

edited Nov 21 '18 at 10:52


Fantômas
32.6k156389
32.6k156389
asked Nov 21 '18 at 10:14


robert.littlerobert.little
346211
346211
1
You can do that stuff inside a baseactivity with a specific layout you needed. From that layout you can create fragments and make your other ui logic inside them.
– denizt
Nov 21 '18 at 10:27
add a comment |
1
You can do that stuff inside a baseactivity with a specific layout you needed. From that layout you can create fragments and make your other ui logic inside them.
– denizt
Nov 21 '18 at 10:27
1
1
You can do that stuff inside a baseactivity with a specific layout you needed. From that layout you can create fragments and make your other ui logic inside them.
– denizt
Nov 21 '18 at 10:27
You can do that stuff inside a baseactivity with a specific layout you needed. From that layout you can create fragments and make your other ui logic inside them.
– denizt
Nov 21 '18 at 10:27
add a comment |
3 Answers
3
active
oldest
votes
best way is creating a custom xml file with any name you want and you can use it any number of times you want without any copy and paste.
step 1: creating custom layout named footer_message .
<TextView
android:layout_width="match_content"
android:layout_height="wrap_content"
android:text="You are Offline"/>
step 2: adding that custom layout in another xml which you want that msg.
<include
android:id="@+id/footer_message"
layout="@layout/footer_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
add a comment |
Use custom BottomSheetDialog
. You do not have to inclue it in layout file. Instead, you will call it programmatically.
BottomMessageDialog:
public class BottomMessageDialog extends BottomSheetDialog {
public BottomMessageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.dialog_bottom_message);
}
}
dialog_bottom_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="You are offline"
android:textSize="18sp"
android:gravity="center"/>
</LinearLayout>
Call it:
BottomMessageDialog bottomMessageDialog = new BottomMessageDialog(MainActivity.this);
bottomMessageDialog.show();
Hope it will help.
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
add a comment |
create an xml file
footer.xml
make your layout in it and write this code in the xml files where you want that footer
<include
android:layout_height="wrap_content"
android:layout_width="fill_parent"
layout="@layout/footer"
android:id="@+id/footer"/>
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" isandroid:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.
– robert.little
Nov 21 '18 at 12:57
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409767%2flayout-element-defined-globally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
best way is creating a custom xml file with any name you want and you can use it any number of times you want without any copy and paste.
step 1: creating custom layout named footer_message .
<TextView
android:layout_width="match_content"
android:layout_height="wrap_content"
android:text="You are Offline"/>
step 2: adding that custom layout in another xml which you want that msg.
<include
android:id="@+id/footer_message"
layout="@layout/footer_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
add a comment |
best way is creating a custom xml file with any name you want and you can use it any number of times you want without any copy and paste.
step 1: creating custom layout named footer_message .
<TextView
android:layout_width="match_content"
android:layout_height="wrap_content"
android:text="You are Offline"/>
step 2: adding that custom layout in another xml which you want that msg.
<include
android:id="@+id/footer_message"
layout="@layout/footer_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
add a comment |
best way is creating a custom xml file with any name you want and you can use it any number of times you want without any copy and paste.
step 1: creating custom layout named footer_message .
<TextView
android:layout_width="match_content"
android:layout_height="wrap_content"
android:text="You are Offline"/>
step 2: adding that custom layout in another xml which you want that msg.
<include
android:id="@+id/footer_message"
layout="@layout/footer_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
best way is creating a custom xml file with any name you want and you can use it any number of times you want without any copy and paste.
step 1: creating custom layout named footer_message .
<TextView
android:layout_width="match_content"
android:layout_height="wrap_content"
android:text="You are Offline"/>
step 2: adding that custom layout in another xml which you want that msg.
<include
android:id="@+id/footer_message"
layout="@layout/footer_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
edited Dec 31 '18 at 12:41
answered Nov 21 '18 at 11:20
Anusha MathurAnusha Mathur
7513
7513
add a comment |
add a comment |
Use custom BottomSheetDialog
. You do not have to inclue it in layout file. Instead, you will call it programmatically.
BottomMessageDialog:
public class BottomMessageDialog extends BottomSheetDialog {
public BottomMessageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.dialog_bottom_message);
}
}
dialog_bottom_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="You are offline"
android:textSize="18sp"
android:gravity="center"/>
</LinearLayout>
Call it:
BottomMessageDialog bottomMessageDialog = new BottomMessageDialog(MainActivity.this);
bottomMessageDialog.show();
Hope it will help.
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
add a comment |
Use custom BottomSheetDialog
. You do not have to inclue it in layout file. Instead, you will call it programmatically.
BottomMessageDialog:
public class BottomMessageDialog extends BottomSheetDialog {
public BottomMessageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.dialog_bottom_message);
}
}
dialog_bottom_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="You are offline"
android:textSize="18sp"
android:gravity="center"/>
</LinearLayout>
Call it:
BottomMessageDialog bottomMessageDialog = new BottomMessageDialog(MainActivity.this);
bottomMessageDialog.show();
Hope it will help.
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
add a comment |
Use custom BottomSheetDialog
. You do not have to inclue it in layout file. Instead, you will call it programmatically.
BottomMessageDialog:
public class BottomMessageDialog extends BottomSheetDialog {
public BottomMessageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.dialog_bottom_message);
}
}
dialog_bottom_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="You are offline"
android:textSize="18sp"
android:gravity="center"/>
</LinearLayout>
Call it:
BottomMessageDialog bottomMessageDialog = new BottomMessageDialog(MainActivity.this);
bottomMessageDialog.show();
Hope it will help.
Use custom BottomSheetDialog
. You do not have to inclue it in layout file. Instead, you will call it programmatically.
BottomMessageDialog:
public class BottomMessageDialog extends BottomSheetDialog {
public BottomMessageDialog(@NonNull Context context) {
super(context);
setContentView(R.layout.dialog_bottom_message);
}
}
dialog_bottom_message.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:text="You are offline"
android:textSize="18sp"
android:gravity="center"/>
</LinearLayout>
Call it:
BottomMessageDialog bottomMessageDialog = new BottomMessageDialog(MainActivity.this);
bottomMessageDialog.show();
Hope it will help.
edited Nov 21 '18 at 10:46
answered Nov 21 '18 at 10:37


tm13tm13
5381320
5381320
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
add a comment |
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
Looks exactly as I wanted but still it's a dialog. The problem is there is an overlay and after clicking on it the dialog disappears. The elements beneath the overlay are not active anymore...
– robert.little
Nov 21 '18 at 12:53
add a comment |
create an xml file
footer.xml
make your layout in it and write this code in the xml files where you want that footer
<include
android:layout_height="wrap_content"
android:layout_width="fill_parent"
layout="@layout/footer"
android:id="@+id/footer"/>
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" isandroid:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.
– robert.little
Nov 21 '18 at 12:57
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
add a comment |
create an xml file
footer.xml
make your layout in it and write this code in the xml files where you want that footer
<include
android:layout_height="wrap_content"
android:layout_width="fill_parent"
layout="@layout/footer"
android:id="@+id/footer"/>
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" isandroid:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.
– robert.little
Nov 21 '18 at 12:57
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
add a comment |
create an xml file
footer.xml
make your layout in it and write this code in the xml files where you want that footer
<include
android:layout_height="wrap_content"
android:layout_width="fill_parent"
layout="@layout/footer"
android:id="@+id/footer"/>
create an xml file
footer.xml
make your layout in it and write this code in the xml files where you want that footer
<include
android:layout_height="wrap_content"
android:layout_width="fill_parent"
layout="@layout/footer"
android:id="@+id/footer"/>
answered Nov 21 '18 at 10:18


Kevin KurienKevin Kurien
548212
548212
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" isandroid:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.
– robert.little
Nov 21 '18 at 12:57
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
add a comment |
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" isandroid:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.
– robert.little
Nov 21 '18 at 12:57
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" is
android:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.– robert.little
Nov 21 '18 at 12:57
Looks good. I had a LinearLayout where I tried to include RelativeLayout footer as you suggested. One of the property of the text element "You are offline" is
android:layout_alignParentBottom="true"
. After I included it to LinearLayout xml file, it wasn't stuck to the bottom anymore.– robert.little
Nov 21 '18 at 12:57
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
I am sorry is this another doubt or you saying it worked. I did not get it
– Kevin Kurien
Nov 21 '18 at 13:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409767%2flayout-element-defined-globally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can do that stuff inside a baseactivity with a specific layout you needed. From that layout you can create fragments and make your other ui logic inside them.
– denizt
Nov 21 '18 at 10:27