Where does AppCompat set the actionbar/toolbar?
The boilerplate that Android Studio generates creates a style that extends Theme.AppCompat.Light.DarkActionBar
. Somehow, this adds an actionbar/toolbar at the top of all my activities.
How does this happen? Where is the bar defined? It's nowhere in the layouts.
android android-studio android-layout
add a comment |
The boilerplate that Android Studio generates creates a style that extends Theme.AppCompat.Light.DarkActionBar
. Somehow, this adds an actionbar/toolbar at the top of all my activities.
How does this happen? Where is the bar defined? It's nowhere in the layouts.
android android-studio android-layout
what do you mean by defined? If you want to see some implementation code, go in your styles.xml, click on Theme.AppCompat.Light.DarkActionBar to select it, right click, then Go to, then Implementation. You'll see some implementation.
– Dr4ke the b4dass
Jan 2 at 0:50
add a comment |
The boilerplate that Android Studio generates creates a style that extends Theme.AppCompat.Light.DarkActionBar
. Somehow, this adds an actionbar/toolbar at the top of all my activities.
How does this happen? Where is the bar defined? It's nowhere in the layouts.
android android-studio android-layout
The boilerplate that Android Studio generates creates a style that extends Theme.AppCompat.Light.DarkActionBar
. Somehow, this adds an actionbar/toolbar at the top of all my activities.
How does this happen? Where is the bar defined? It's nowhere in the layouts.
android android-studio android-layout
android android-studio android-layout
asked Jan 2 at 0:36
Danish KhanDanish Khan
5012615
5012615
what do you mean by defined? If you want to see some implementation code, go in your styles.xml, click on Theme.AppCompat.Light.DarkActionBar to select it, right click, then Go to, then Implementation. You'll see some implementation.
– Dr4ke the b4dass
Jan 2 at 0:50
add a comment |
what do you mean by defined? If you want to see some implementation code, go in your styles.xml, click on Theme.AppCompat.Light.DarkActionBar to select it, right click, then Go to, then Implementation. You'll see some implementation.
– Dr4ke the b4dass
Jan 2 at 0:50
what do you mean by defined? If you want to see some implementation code, go in your styles.xml, click on Theme.AppCompat.Light.DarkActionBar to select it, right click, then Go to, then Implementation. You'll see some implementation.
– Dr4ke the b4dass
Jan 2 at 0:50
what do you mean by defined? If you want to see some implementation code, go in your styles.xml, click on Theme.AppCompat.Light.DarkActionBar to select it, right click, then Go to, then Implementation. You'll see some implementation.
– Dr4ke the b4dass
Jan 2 at 0:50
add a comment |
3 Answers
3
active
oldest
votes
Android studio inflates custom Views or ViewGroups they have already defined, most of these you cannot see because they are private classes.
Here is an example of how you would do this in code.
class Test extends android.support.v7.widget.AppCompatTextView {
public Test(Context context) {
super(context);
initTestView(null);
}
public Test(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initTestView(attrs);
}
public Test(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initTestView(attrs);
}
public void initTestView(AttributeSet as) {
if (as != null) {
TypedArray ta = getContext().obtainStyledAttributes(as, R.styleable.Test);
String textOverride = ta.getString(R.styleable.Test_override);
ta.recycle();
setText("Test: " + textOverride);
}
}
}
Then you would define a styleable in the app/src/main/res/values/attr.xml
<declare-styleable name="Test">
<attr name="override" format="string" />
</declare-styleable>
Now when Android inflates this, it can see your custom class as well as attributes to construct it with. If you were to add this to a layout it would automatically generate an example view of my code. This is the same as Androids core styled Views/ViewGroups and they will oftentimes have default values or visible representations of these class as they are inflated and attached to their parent views.
To make it perfectly clear, when you add an Android View into your layout, let's say for simplicity .
<TextView
android:id="@+id/hello"
android:text="@string/greeting"/>
The class for TextView is doing similar stuff to my examples initTestView
method, by grabbing its typed properties (text, id) and populating the Views or values it has internally. It is, at its core, how Android glues xml values to their class representations.
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
|
show 2 more comments
With the help of Chris Sullivan we figured out what was going on. This is an estimated guess.
It turns out that using the Theme.AppCompat.Light.DarkActionBar
style/theme just adds some type top margin to all activities and fills them with the primary color. This makes it look in the Android editor as if there's an app bar/toolbar/action bar, but it's just smoke and mirrors.
The actual app bar is added at runtime by AppCompatActivity.
add a comment |
This is defined in the styles xml. Your apptheme extends from it. If you want it to be gone you can extend another style for example Theme.AppCompat.Light.NoActionBar
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
1
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
|
show 2 more comments
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%2f54000059%2fwhere-does-appcompat-set-the-actionbar-toolbar%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
Android studio inflates custom Views or ViewGroups they have already defined, most of these you cannot see because they are private classes.
Here is an example of how you would do this in code.
class Test extends android.support.v7.widget.AppCompatTextView {
public Test(Context context) {
super(context);
initTestView(null);
}
public Test(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initTestView(attrs);
}
public Test(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initTestView(attrs);
}
public void initTestView(AttributeSet as) {
if (as != null) {
TypedArray ta = getContext().obtainStyledAttributes(as, R.styleable.Test);
String textOverride = ta.getString(R.styleable.Test_override);
ta.recycle();
setText("Test: " + textOverride);
}
}
}
Then you would define a styleable in the app/src/main/res/values/attr.xml
<declare-styleable name="Test">
<attr name="override" format="string" />
</declare-styleable>
Now when Android inflates this, it can see your custom class as well as attributes to construct it with. If you were to add this to a layout it would automatically generate an example view of my code. This is the same as Androids core styled Views/ViewGroups and they will oftentimes have default values or visible representations of these class as they are inflated and attached to their parent views.
To make it perfectly clear, when you add an Android View into your layout, let's say for simplicity .
<TextView
android:id="@+id/hello"
android:text="@string/greeting"/>
The class for TextView is doing similar stuff to my examples initTestView
method, by grabbing its typed properties (text, id) and populating the Views or values it has internally. It is, at its core, how Android glues xml values to their class representations.
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
|
show 2 more comments
Android studio inflates custom Views or ViewGroups they have already defined, most of these you cannot see because they are private classes.
Here is an example of how you would do this in code.
class Test extends android.support.v7.widget.AppCompatTextView {
public Test(Context context) {
super(context);
initTestView(null);
}
public Test(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initTestView(attrs);
}
public Test(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initTestView(attrs);
}
public void initTestView(AttributeSet as) {
if (as != null) {
TypedArray ta = getContext().obtainStyledAttributes(as, R.styleable.Test);
String textOverride = ta.getString(R.styleable.Test_override);
ta.recycle();
setText("Test: " + textOverride);
}
}
}
Then you would define a styleable in the app/src/main/res/values/attr.xml
<declare-styleable name="Test">
<attr name="override" format="string" />
</declare-styleable>
Now when Android inflates this, it can see your custom class as well as attributes to construct it with. If you were to add this to a layout it would automatically generate an example view of my code. This is the same as Androids core styled Views/ViewGroups and they will oftentimes have default values or visible representations of these class as they are inflated and attached to their parent views.
To make it perfectly clear, when you add an Android View into your layout, let's say for simplicity .
<TextView
android:id="@+id/hello"
android:text="@string/greeting"/>
The class for TextView is doing similar stuff to my examples initTestView
method, by grabbing its typed properties (text, id) and populating the Views or values it has internally. It is, at its core, how Android glues xml values to their class representations.
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
|
show 2 more comments
Android studio inflates custom Views or ViewGroups they have already defined, most of these you cannot see because they are private classes.
Here is an example of how you would do this in code.
class Test extends android.support.v7.widget.AppCompatTextView {
public Test(Context context) {
super(context);
initTestView(null);
}
public Test(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initTestView(attrs);
}
public Test(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initTestView(attrs);
}
public void initTestView(AttributeSet as) {
if (as != null) {
TypedArray ta = getContext().obtainStyledAttributes(as, R.styleable.Test);
String textOverride = ta.getString(R.styleable.Test_override);
ta.recycle();
setText("Test: " + textOverride);
}
}
}
Then you would define a styleable in the app/src/main/res/values/attr.xml
<declare-styleable name="Test">
<attr name="override" format="string" />
</declare-styleable>
Now when Android inflates this, it can see your custom class as well as attributes to construct it with. If you were to add this to a layout it would automatically generate an example view of my code. This is the same as Androids core styled Views/ViewGroups and they will oftentimes have default values or visible representations of these class as they are inflated and attached to their parent views.
To make it perfectly clear, when you add an Android View into your layout, let's say for simplicity .
<TextView
android:id="@+id/hello"
android:text="@string/greeting"/>
The class for TextView is doing similar stuff to my examples initTestView
method, by grabbing its typed properties (text, id) and populating the Views or values it has internally. It is, at its core, how Android glues xml values to their class representations.
Android studio inflates custom Views or ViewGroups they have already defined, most of these you cannot see because they are private classes.
Here is an example of how you would do this in code.
class Test extends android.support.v7.widget.AppCompatTextView {
public Test(Context context) {
super(context);
initTestView(null);
}
public Test(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
initTestView(attrs);
}
public Test(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initTestView(attrs);
}
public void initTestView(AttributeSet as) {
if (as != null) {
TypedArray ta = getContext().obtainStyledAttributes(as, R.styleable.Test);
String textOverride = ta.getString(R.styleable.Test_override);
ta.recycle();
setText("Test: " + textOverride);
}
}
}
Then you would define a styleable in the app/src/main/res/values/attr.xml
<declare-styleable name="Test">
<attr name="override" format="string" />
</declare-styleable>
Now when Android inflates this, it can see your custom class as well as attributes to construct it with. If you were to add this to a layout it would automatically generate an example view of my code. This is the same as Androids core styled Views/ViewGroups and they will oftentimes have default values or visible representations of these class as they are inflated and attached to their parent views.
To make it perfectly clear, when you add an Android View into your layout, let's say for simplicity .
<TextView
android:id="@+id/hello"
android:text="@string/greeting"/>
The class for TextView is doing similar stuff to my examples initTestView
method, by grabbing its typed properties (text, id) and populating the Views or values it has internally. It is, at its core, how Android glues xml values to their class representations.
edited Jan 2 at 1:24
answered Jan 2 at 0:51
Chris SullivanChris Sullivan
55658
55658
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
|
show 2 more comments
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
"The bar is defined in an already generated android style", that's exactly my question, how is the style.xml adding a bar to my activity... I know how to remove it, thanks.
– Danish Khan
Jan 2 at 0:55
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
Its inflated by android automatically and populated. As part of the build process Android generates R classes as well as pulls in styled components that their appcompat library uses. This can include custom Views or Viewgroups that are only visible to Android (i.e. private classes). Some of the code you cannot see, but if you want a close approximation for whats going on play with the newer appCompat Toolbar class.
– Chris Sullivan
Jan 2 at 1:00
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
The latest edit is starting to make more sense :) But I'm still not clear on something, in your example, I would need to add <Test> to my layout for it to be inflated and shown in the "Design" tab in Android Studio, but I never did this with the toolbar that gets added as part of AppCompat :/
– Danish Khan
Jan 2 at 1:15
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Yes, but its the same principle. Adding <android.whatever.path.ActionBar> does exactly the same thing as my example you just can't see the exposed class.
– Chris Sullivan
Jan 2 at 1:21
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
Also updated the answer one last time illustrating the point with a TextView
– Chris Sullivan
Jan 2 at 1:26
|
show 2 more comments
With the help of Chris Sullivan we figured out what was going on. This is an estimated guess.
It turns out that using the Theme.AppCompat.Light.DarkActionBar
style/theme just adds some type top margin to all activities and fills them with the primary color. This makes it look in the Android editor as if there's an app bar/toolbar/action bar, but it's just smoke and mirrors.
The actual app bar is added at runtime by AppCompatActivity.
add a comment |
With the help of Chris Sullivan we figured out what was going on. This is an estimated guess.
It turns out that using the Theme.AppCompat.Light.DarkActionBar
style/theme just adds some type top margin to all activities and fills them with the primary color. This makes it look in the Android editor as if there's an app bar/toolbar/action bar, but it's just smoke and mirrors.
The actual app bar is added at runtime by AppCompatActivity.
add a comment |
With the help of Chris Sullivan we figured out what was going on. This is an estimated guess.
It turns out that using the Theme.AppCompat.Light.DarkActionBar
style/theme just adds some type top margin to all activities and fills them with the primary color. This makes it look in the Android editor as if there's an app bar/toolbar/action bar, but it's just smoke and mirrors.
The actual app bar is added at runtime by AppCompatActivity.
With the help of Chris Sullivan we figured out what was going on. This is an estimated guess.
It turns out that using the Theme.AppCompat.Light.DarkActionBar
style/theme just adds some type top margin to all activities and fills them with the primary color. This makes it look in the Android editor as if there's an app bar/toolbar/action bar, but it's just smoke and mirrors.
The actual app bar is added at runtime by AppCompatActivity.
answered Jan 2 at 9:17
Danish KhanDanish Khan
5012615
5012615
add a comment |
add a comment |
This is defined in the styles xml. Your apptheme extends from it. If you want it to be gone you can extend another style for example Theme.AppCompat.Light.NoActionBar
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
1
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
|
show 2 more comments
This is defined in the styles xml. Your apptheme extends from it. If you want it to be gone you can extend another style for example Theme.AppCompat.Light.NoActionBar
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
1
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
|
show 2 more comments
This is defined in the styles xml. Your apptheme extends from it. If you want it to be gone you can extend another style for example Theme.AppCompat.Light.NoActionBar
This is defined in the styles xml. Your apptheme extends from it. If you want it to be gone you can extend another style for example Theme.AppCompat.Light.NoActionBar
answered Jan 2 at 0:39
PrisonMikePrisonMike
94411625
94411625
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
1
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
|
show 2 more comments
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
1
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
But how can you define an actionbar from styles.xml? Shouldn't this be in a layout.xml?
– Danish Khan
Jan 2 at 0:43
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
you create a menu.xml file in the res and use the onCreateOptionsMenu callback in the activity to inflate it
– PrisonMike
Jan 2 at 0:44
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
It is possible to define it in your layout, but then you should use a toolbar and set that as the actionbar in onCreate with the setSupportActionbar method, but i recommend the onCreateOptions menu if you don't need to customize alot
– PrisonMike
Jan 2 at 0:45
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
I know how to define it from code. My question is, how is this placed in my view and displayed in the Android Studio editor without any of this code running and just by adding a theme?
– Danish Khan
Jan 2 at 0:49
1
1
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
> Can you define UI components in styles.xml? partially, I will update my code example.
– Chris Sullivan
Jan 2 at 1:01
|
show 2 more comments
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%2f54000059%2fwhere-does-appcompat-set-the-actionbar-toolbar%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
what do you mean by defined? If you want to see some implementation code, go in your styles.xml, click on Theme.AppCompat.Light.DarkActionBar to select it, right click, then Go to, then Implementation. You'll see some implementation.
– Dr4ke the b4dass
Jan 2 at 0:50