Android title buttons - android

I am trying to reproduce the account chooser widget that the GMail app has on top right.
I know already how to put things in the title but i have several problems:
I've tried putting a normal button in the title but it doesn't fit
It looks like the size of the title is bigger than what it is, for example if I put a normal button there, there is no way of making it the proper height, in fact goes below the app like if half of the title space was hidden below
I thought it might be a clickable label with a rectangular shape, but I tried it and no way to make it work.
Any hint?

Looking at the layout using the hierarchy viewer it seems like it really is just a Button inside a LinearLayout. The only interesting part is that the LinearLayout's layout_height is set to MATCH_PARENT (which is just the newer version of FILL_PARENT) where its parent the RelativeLayout has a hardcoded layout_height of 54.
I'm not sure if this is of help for you but maybe it can point you in the right direction.

Related

Certain Options Missing in Android Studio

enter image description here
Absolute beginner here, and I can't seem to access all of my options in android studio. For example, when I put in a textview in the layout, for the layout_width, fill parent option is not appearing, even though I definitely remember it to have been there when I used in briefly on my friend's computer.
It's not there as it's not an optimal option:
Important: MATCH_PARENT is not recommended for widgets contained in a
ConstraintLayout. Similar behavior can be defined by using
MATCH_CONSTRAINT with the corresponding left/right or top/bottom
constraints being set to "parent".
(source)
maybe you saw that option on a different layout (eg. linear).

Align Toolbar title and SearchView with list content with avatars

I'm trying to follow the material guidelines and I aligned the Toolbar title with the avatar like the image below following the instructions of #ChrisBanes in this answer.
My issue now is that when the SearchView is activated, it's not aligned anymore as seen in the second image. (It was aligned before changing the inset)
Any ideas of how I can align both things instead of having to choose between one or the other?
If you want to align avatar with search-view then you need remove space of homeup button and search-view.
FYI: search view behavior is different in large size device so you can go with custom action-bar.
I solved it by using app:titleMarginStart="16dp" instead of changing the contentInset. I have tested it only in a xhdpi phone, though.

How to disable auto alignment?

I'm building an android project and I'm using eclipse.
I just can't figure out how to disable the annoying auto alignment.
I just want to place buttons wherever I want to drop them on the GUI interface but it just keeps
to align them one to another. I've tried to delete those alignment lines in the xml code
but it still brings them back as I move the buttons on the GUI interface.
Is there an way to disable that function?
Thank you,
Alex
Is there an way to disable that function?
Not in a way that you will find satisfactory, I suspect.
You have not really explained what the "alignment lines" are, so we are forced to guess. My guess is that the "alignment lines" are because you are working with a RelativeLayout container. Quoting the JavaDocs for RelativeLayout, RelativeLayout is:
A Layout where the positions of the children can be described in relation to each other or to the parent.
And, quoting the guide for RelativeLayout:
RelativeLayout is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left of center).
Hence, the "alignment lines" are there, and are replaced by the GUI builder, because they are the point behind using a RelativeLayout container.
Of course, you are welcome to change the container that you are working with to something else.
However, in general, Android does not really support very well your stated objective ("I just want to place buttons wherever I want to drop them on the GUI interface"). Just as you don't do that in Web development, you don't do that in Android development, and for much the same reason: you need to take different sizes into account (browser window size for Web, screen size for Android). RelativeLayout, LinearLayout, TableLayout, and GridLayout are all designed to have you specify widgets plus rules for positioning and sizing, so that you can design a UI that will accommodate the difference between a 3" and a 4.5" screen, for example. This is akin to using HTML tags and CSS rules to define content and its positioning in a Web page. Eclipse's drag-and-drop GUI builder for Android can assist in your definitions of these rules, as you are perhaps seeing with your "alignment lines" for RelativeLayout.
I think I may be able to help. If you set your layout to Relative Layout you can drag and drop any of the views wherever on the eclipse GUI.

Transparent layout - not transparent on Android 2.3

I have a transparent layout used for holding a banner advert in my app. The layout sits on top of my game area constantly, but the ads only appear once in a while. The code works as follows:
transparent_linearlayout_to_hold_banner.setBackgroundColor(Color.TRANSPARENT);
game_frame_layout.addView(transparent_linearlayout_to_hold_banner);
setContentView(game_frame_layout);
When I want an ad to be shown I do a
transparent_linearlayout_to_hold_banner.addView(adView);
When I want the ad to disappear I do a
transparent_linearlayout_to_hold_banner.removeView(adView);
This works perfectly on my Galaxy S !! with 4.0.3, but on my Galaxy tab with 2.3 I find that my transparent_linearlayout_to_hold_banner turns black as soon as the add appears, and remains black forever more, even when the ad is removed.
Any idea what is happening?... and how to fix it?
EDIT: after some experimentation, I worked out that the colour of the layout is not changing, but the alpha channel is. My guess is that perhaps the SDK of the banner ad system is calling some function(s) to make sure that the banner itself is not transparent, and then (depending on the OS version) this is having the side effect of making its parent layout non-transparent.
Try making the layout non transparent before adding the ad banner.
When you want to remove the ad, remove the ad banner view and make the layout transparent again.
Can you try adding this line again after you remove the ad.
transparent_linearlayout_to_hold_banner.setBackgroundColor(Color.TRANSPARENT);
If you're using admob, try latest 6.0 library, it has several improvements (as I can see) in control over the look of ad, it seems to pay more attention to the attributes described in Best Practices: Specifying ad colors. I had similar problem with previous release of the library. Yet, it doesn't allow alpha-channel, so you wouldn't be able to specify transparent background of the ad, but it may solve your problem.
try to make the layout that you want to be transparent in XML, not dynamically. I had such problems on dynamically added ListView with transparent Items.
You have a game here, so of course what I suggested might not work, or will be hard to do, but you can Use a FrameLayout to put your layout on which you draw, and the transparent one on top of it. Also note, in such case the touches will go to the ad layout. It can be prevented, but is a bit like of a hack (I did it by the way once).
I don't know if this will work, but give a try.
some ideas:
can you simply remove the line of setting the background to the lineraLayout :
transparent_linearlayout_to_hold_banner.setBackgroundColor(Color.TRANSPARENT);
?
also , instead of removing and adding the adView , can you instead toggle the visibility of the linearLayout (or the adView ) ?

Gmail tablet style scroll bars with transparent actionbar

I've been trying stuff and searching for the last couple of hours and got no where so I thought I'd ask here.
Basically the Honeycomb version of Gmail has a listview on the right for it's message list and when you scroll the listview the items go under the actionbar which appears to have some form of gradient on it with #00FFFFFF at the bottom going up to #FFFFFFFF at the top giving the impression of the items fading out.
But they important thing to notice here is that the SCROLLBAR on the listview never goes underneath the ActionBar! and the default top position for the listview is underneath the scrollbar.
I've tried to implement a similar style layout for my app with a scrollview that scrolls underneath the actionbar which has an alpha set on it, it looks all nice and well but the scrollbars go underneath as well! :( and it makes it look a bit weird, it's not a nice option.
I've achieved what I have so far by using
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
and
getActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar_bg));
which is a an XML drawable that simply has a color of #BB000000 (no gradient just yet)
this is the current effect, the scrollbar can be seen underneath the actionbar :(
this is the desired effect with the scrollbar never going into the actionbar but the content does scroll up underneath it
Edit: I think this probably uses something custom in Google and have all but given up figuring it out
call this before super.onCreate(savedInstanceState); in onCreate of your activity
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
More: http://developer.android.com/reference/android/view/Window.html#FEATURE_ACTION_BAR_OVERLAY
I can't see an easy way of doing this but I have come up with two possible solutions. There could well be a much better option that I couldn't see obviously.
The first and easiest, is to create a 9patch background file for you ActionBar that has an expanding gradient area and a fixed opaque area at the right hand side, the same side as your scroll bar. This way the scrollbar would still go under the ActionBar, but it would be hidden. However it would have the affect of the scrollbar disappearing / getting smaller.
Another option would be to edit the scrollbar thumb in the xml like this:
<ListView android:scrollbarThumbVertical="#drawable/YOUR_CUSTOM_THUMB" ></ListView>
Then create a scrollbar thumb with a transparent offset at the top.
Thinking about it I think the second option is probably the best to go for and will give you the best result. I realise it's a pretty crappy hack. Looking into a code way of doing it, I think you would have to extend a number of classes and override a load of methods.
simply use:
getActionBar().setBackgroundDrawable(null);

Categories

Resources