This question already has answers here:
Actionbar background is not being changed
(2 answers)
Closed 8 years ago.
In my application, I am using actionbarsherlock. I use
getSupportActionBar().setBackgroundDrwable(R.drawable.test).
It works fine, the color is showed as expected, however when I go to another activity and go back to the main activity. The bar color is changed to black (in my program, I dont set black for the backgrounddrawble and just call setSupportAction().setBackgroundDrawable in onStart()). However, if I change the code to
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(0xff550000)));
The app works fine. When I click on back button, the color is set to 0xff55000 which is expected.
I will suggest not to use the color code directly this way while you are trying to set the color programmatically. It will not take it. just try out this way..
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(mContext.getResources().getColor(Color.BLACK)));
Hope it will work for you.
It doesn't work well for me either, specially if I use with the navigation drawer toggle list. In my case, if i don't use the toggle, the background goes white during a second and then load the background drawable. If I use the toggle, the background remains white.
I had to use a custom view to achive the effect I wanted to get instead of changing the background.
I have almost the same issue, it happens that calling getActionBar().setBackgroundDrawable twice does not work.
If I only call it only once in the onCreate is works. If I put the code in the onResume, it works for the first onResume, but it is set to grey for any other onResume
Related
I'm working on an app that only uses a single Activity and switches out fragments as they are needed with the navigation drawer.
Now we want to navigate back from one of these fragments by using the homeAsUp button in the ActionBar.
I have followed all the steps to set the button up. From disabling the navigation drawer setDrawerIndicatorEnabled(false) and calling setDisplayHomeAsUpEnabled(true) in the fragment's onCreateView().
I also set setHomeButtonEnabled(true) in the MainActivity's onCreate() however because the app is already in the MainActivity, we cannot specify a Parent Activity.
Whenever I run a fresh install of the app, the homeAsUp button works and is registered in the onBackPressed(), not onOptionsItemSelected() method. However, when I close the app and run it again the button does not even register clicks.
In onBackPressed() I check a few conditions, but it does not block the button press.
In onOptionsItemSelected() I check for android.R.id.home.
Unfortunately, I cannot post the code.
This post describes what I'm trying to achieve: Switching between Android Navigation Drawer image and Up caret when using fragments
I managed to fix the issue I was experiencing. It was a very simple mistake.
Because I'm not the original author of this code, I went through the MainActivity thoroughly.
As it turns out the original author called setDisplayHomeAsUpEnabled in the onCreate function (which is extremely long), but near the end he also called setSupportActionBar, which made the first call of setDisplayHomeAsUpEnabled useless. Moving setDisplayHomeAsUpEnabled below setSupportActionBar fixed my problem.
If you did everything correctly, make sure that your code is written in the correct order.
Furthermore, if you use custom toolbars in other fragments, remember to set your original Support Action Bar by calling setSupportActionBar(toolbar.find(this)) in onResume of your MainActivity.
I have android listview with custom adapter.I have implemented the AdapterView.OnItemClickListener . Onclick it launches a new fragment. Now all of that works, but the listview Item turns grey after click in the background.I need it to be transparent/white.
So I thought it must be in a selected state which I somehow have to disable.
This is what I have tried so far without any luck.
listview.setSelector(android.R.color.transparent);
listView.setFocusable(false);
listView.setActivated(false);
Other options such as
in onItemClick(){
view.setBackgroundColor(ContextCompat.getColor(getContext(),
android.R.color.transparent));
interesting this seems to be semi working as if I use color.red. I can see it getting red momentarily before the fragment dialog shows at that point I can see it turning grey again in the background.
Also the odd part is that this last piece of code i.e
view.setBackgroundColor(ContextCompat.getColor(getContext(),
android.R.color.transparent)
works in onItemLongPress. And it stays transparent as expected.
i have an activity which is to be converted to an popup. so i used
SetTheme(Android.Resource.Style.ThemeDialog);
to make it look like an popup. but the problem is it looks like a popup but previous activity is not visible on back. i get a black background. what i am doing wrong. little help will be great.
i couldn't fix it using SetTheme(Android.Resource.Style.ThemeDialog);
so i changed the activity to dialog fragment and now it works fine.
I have following problem:
I want to create a toolbar, with general setting for device (TV) by adding view to window manager. My toolbar is visible in the bottom of screen and it is an overlay on currently selected application. It has following parameters/flags:
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
-WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
-WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
-WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
-PixelFormat.TRANSLUCENT
When I click on the toolbar it is working fine.
When I click on the background, toolbar is still at foreground, and background application is working fine.
The problem starts, when I am populating ListView from my toolbar. With those parameters, onClick and onSelectItem listeners are not working on that ListView. When I remove FLAG_NOT_FOCUSABLE, listeners start to work, but I cannot use background application any more. I have to close my toolbar in order to get focus on the background.
Do you have any idea, how to make both ListView and background application responsiveness?
Thanks in advance, for every answer/
This is known issue with PixelFormat.TRANSLUCENT, try PixelFormat.TRANSPARENT
I'm changing the background drawable for my buttons when they're clicked (as they trigger functions such as play/record). While playing/recording, the button glows (a different 9-patch is set as the background) and turns into a stop button. My problem is that currently I'm using:
b.setBackgroundResource(R.drawable.btn_default_normal);
to set the background back again afterwards. This works, but the normal behaviour when I use setEnabled(false) is lost. After a button has been used, and reset to normal, it retains the normal background (rather than the dimmed one) when disabled. The text still changes colour though. Is there a way of 'resetting' the background of the button to default, so that it retains its normal behaviour?
Ok, I got the answer from this blog post in the end. What you have to do is create an xml document with all the different button states, and assign that rather than just an image to the background.