I've created a new project in Android Studio and there is a UI bug for the interface and I am not able to fix it. I don't understand what is this problem.
Basically it appears a top margin / a top padding for the fragment. In the "night theme" the problem is not present and the only thing I change between light and night is colours (in styles>themes)...
I explain a moment the structure of my project: there is the main activity, which contains "Nav_menu" and the "Fragment" view. This problem is present is all the fragments, so I thought it was a problem in Main... but I cannot understand actually.
I set manually 0dp to padding and margin, but nothing changes... do any others got this problem?
Let me show some images:
I think you use theme action bar set to be true, In every fragment action bar or title bar is showing because fragment is opening through an activity, try to set false for action bar or whatever in style theme
Related
I'm trying to add the edge-to-edge stuff for the gesture navigation bar to the Tip Time app from Google. I added the transparent navigationBarColor XML tag to themes.xml as well as the following code to the onCreate() function of MainActivity.kt:
This was directly copy-pasted from the documentation. Android Studio says that "it cannot find a parameter with this name" for each of the three margins. I noticed that changing the parenthesis right after <ViewGroup.MarginLayoutParams> to curly braces fixes the compiler error. Maybe the documentation is just wrong?
Anyways, even after fixing that, the app still doesn't look right:
As you can see, the entire view gets shifted up slightly and the "Cost of Service" TextView is partially cut-off by the app bar. What would I need to change to implement the system/navigation bar insets for edge-to-edge content so the UI looks nice? Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
As per documentation for edge to edge contents:
Draw behind the status bar if it makes sense for your content and
layout, such as in the case of full-width imagery. To do this, use
APIs such as AppBarLayout, which defines an app bar pinned to the top
of the screen.
So, while handing the window insets (especially the top one), you can't use the default ActionBar, instead you need to customize that with AppBarLayout and ToolBar, and to make it act as the ActionBar, use setSupportActionBar(), and a NoActionBar app theme; it'd be <style name="Theme.TipTime" parent="Theme.MaterialComponents.DayNight.NoActionBar"> in the shared repo.
the entire view gets shifted up slightly and the "Cost of Service" text field is partially cut-off by the app bar.
The reason that the sample uses the default ActionBar instead of a customized one; when it comes to handle the top window insets, it won't affect the default ActionBar; notice that you pass in the activity's root layout to setOnApplyWindowInsetsListener callback, and as the ActionBar is not a part of the activity, it won't be affected. Therefore the activity is shifted up behind the ActionBar when the top inset is removed. So, to solve this you have either to totally remove the default ActionBar or to use a custom toolbar instead.
Also, as a side-question, how can I change the dark blue color of the system status bar to match the color of the app bar so that they look blended?
Use a transparent status bar color in the app's theme:
<item name="android:statusBarColor" tools:targetApi="l">#android:color/transparent</item>
My bottom navigation bar recreates whenever I switch from light mode to dark mode and viceversa.
The scenario is this: I'm navigating to a whole new fragment which doesn't have the bottom navigation bar.. now, if I switch from light mode to dark mode, the bottom navigation bar appears when it shouldn't.
How should I deal with it?
Thank you everyone in advance
When the app’s theme changes, App undergoes configuration changes and thus underlying activities recreate themselves.
Here is what Documentation Says:
When the app’s theme changes (either through the system setting or AppCompat) it triggers a uiMode configuration change. This means that Activities will be automatically recreated.
It means if at the start of activity you are setting a fragment that has no bottom navigation bar then you will end up seeing a fragment with no bottom navigation bar after changing the theme. That's what I can say with the little information I have from the question.
I hope this helps :)
If you are using android:background on your BottomNavigationView, change it to app:itemBackground
I am using bottom navigation to change fragments. For whatever reason, I need to change Fragment if the user taps a particular button. This method working fine, except a little aesthetic problem. If I change fragment programmatically, the bottom navigation icon color won't change.
For handling color change, I am using selector XML right now, but I am ready to use other solutions, to handle this little problem.
please follow this code, it may help you bottomNavigationView.setSelectedItemId(R.id.navigation_home);
I am building an app that uses ActionBarSherlock. I need to change it's layout so there is no padding arround tab icons. Now it looks like that:
| tab1 | tab2 | tab3 | t
But i want it like that:
|tab1|tab2|tab3|tab4|
I've manage to do so on normal size screens by changing that file:
library/res/values/abs__styles.xml
However on my Galaxy S3 still has padding, I tried changing paddings from:
library/res/values-xlarge/abs__dimens.xml
but no effect. I also tried to remove it but still no changes.
edit:
Just for information, I am using only icons but no text for top. All my icons are in drawable-hdpi, could that be a problem? I don't think so because they are not reseized or anything only paddings apper :S
that one is in values.
so I also tried comment out all lines with
<dimen name="abs__action_bar_icon_vertical_padding">0dip</dimen>
but no effect…
If your Galaxy S3 is running ICS or later, ABS will use the native action bar. Any changes you make to the library will have no effect.
Action Bar Sherlock library has some limitations in it.
Limitation 1 : Adjusting of Action menu items in action bar is not possible
Description :
You can have different action menu items in the action bar and also you can set the icons for that items in the action bar. But, adjusting padding between action items, Removing Toast for the action items in the action bar it is impossible. Because Action bar Sherlock uses native action bar. Only look and feel is similar to ICS, but behavior is restricted.
Limitation 2 : Activity Recreation
Description :
When Screen orientation changes, It will recreate activity which is in active. So User Interface will get updated and also it doesn't save the state of the application or activity..
Be Aware of Action Bar Sherlock
I wouldn't use ABS directly for Tab navigation. Consider using a Viewpager and ViewPagerIndicator, which is comatible with ABS (same author), and there you have a lot more control of the appearance . This way the user can also swip left-right to switch tabs.
Does this happen no matter what? I honestly haven't played too much with a native actionbar. What if you do something like an inset drawable? This would kind-of change how it's drawn and may shrink the icon, but might be a solution until you find something better.
I have an application which uses a custom title bar. However, when my application launches, I noticed that the default title bar is shown for a brief period of time. My problem is I don't want to show the default title bar while my application is loading. How do I hide the title bar while my application is loading so that there will be no hint of it and then show it afterwards?
So far, I tried the following solutions but none have worked:
Hide the title bar in XML and then set the custom title bar in code. (Problem encountered: I received an error message saying: "You cannot combine custom titles with other title features".)
In XML:
<item name="android:windowNoTitle">true</item>
In onCreate method:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
//... some code goes here
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_header);
Set the size of the title bar in XML to 0. Then change it's size via code later. (Problem encountered: I don't know how to set the size of title bar in code. Is it possible? I tried getWindow().setAttributes() and getWindow().setLayout() but both of them didn't worked.)"
In XML:
<item name="android:windowTitleSize">30dp</item>
Modify windowTitleBackgroundStyle and set a transparent drawable as background. (Problem encountered: The content of the title bar became invisible but a line below the title bar is still visible.)
In XML:
<!-- style used by windowTitleBackgroundStyle -->
<item name="android:background">#drawable/transparent</item>
Some explanations for what you've encountered, hopefully they help lead you in a direction you're happy with.
You've already seen that your theme is used to generate what you see during activity loading. What's happening is the system is generating a temporary/loading window based on your activity's theme as specified in your manifest while your process is still starting up. Your code may not even be running yet, and your own activity will have a different window. This is significant because a number of settings become locked in once the window's decor has been created, but you actually have two chances here. The window your activity uses hasn't been created yet when you see this loading state.
Setting no title in your theme isn't working because it maps to the window feature Window.FEATURE_NO_TITLE. This dominates over any other title window features you may request and once a feature is requested you can't un-request or remove it regardless of whether decor has been initialized yet.
As part of your theme, the title size is giving you predictable issues. Theme attributes can't be changed. However, which theme your activity is using can be changed before your window decor has been initialized. You can specify one theme in your manifest for the activity that will be used during loading and swap it out using setTheme on your activity. (Best place is probably in onCreate before setContentView, where you would otherwise request window features.)
Chances are the line below the title bar you're seeing is the android:windowContentOverlay - the drawable used to supply the drop shadow from the title bar over the content. On most devices the top edge of this shadow would probably appear as a line below the title bar area. You can set this to #null to get rid of the shadow entirely if you want.
What I've done is set the following in my 'application' tag in my manifest.
android:theme="#android:style/Theme.NoTitleBar"
And then, for each activity, I added
android:theme="#style/CustomTheme"
can you try to open application in full screen mode..then on load of application you can exit full screen.that way your title bar will not be visible while in full screen mode. This works in html.not sure if you can use this trick.