I'm using actionbarsherlock.
In order to get action modes on bottom(action modes on bottom) I use
android:uiOptions="splitActionBarWhenNarrow"
But I need to add a button to main action bar, so I use custom view.
View customNav = LayoutInflater.from(this).inflate(R.layout.custom_view, null);
getSupportActionBar().setCustomView(customNav, new
ActionBar.LayoutParams(Gravity.RIGHT));
getSupportActionBar().setDisplayShowCustomEnabled(true);
Here is custom_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="horizontal"
>
<ImageButton
android:id="#+id/btnMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_day"
android:onClick="onMoreClick"/>
It doesn't metter if I use ImageButton or ImageView with the same properties, so I'll talk about ImageButton.
If I use the ImageButton, I get what I want except of that background is gray.
If I add a line to previous custom_view.xml, in order to get transperent background(or use ImageView instead)
android:background="#00000000"
The alpha in icon will be "cropped" and size of button will change.
The question is. How to get button with such sizes as on first image(with default gray background) but with transperent background?
One of the ways to solve a problem is to make a color of the button's background the same as a color of actionbar and it will look like transperent, but I don't think it is a good solution.
You can use image with transparent background. It can be done in photoshop.
Have you considered using an ImageView instead of an ImageButton? Just set your required image in the imageview and use an onclicklistener to detect clicks like you would do for an ImageButton.
Additionally, you can also just specify the width of your ImageButton and set the padding as required (this is if you want to use android:background="#00000000").
i think that you can add to the button
android:background="yourimagethere"; or maybe android:background=NULL
and it will solve the problem
Related
I want to make a button, where left right top and bottom paddings will be same.
But I get something like this:
Here is a layout:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="#+id/people_number_label"
android:text="#string/number_of_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="#+id/people_number"
android:layout_toRightOf="#+id/people_number_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
So the way a Button works is its a text view with a background drawable. That drawable is the one you're seeing. The text will be centered within that drawable, as you see here. If you want the text to appear in line with the prompt, a Button isn't going to work for you. You're better off just making it a TextView and setting an xml background drawable with a rounded rect so it looks like a button, but it actually isn't.
Another thing you can try to do it align_baseline the two view. That should align the text, but may push the prompt down the screen
I'm just starting out in Android and was making a splash screen. I tried to change the default background colour to grey, but apparently I can't use the same attribute twice. How can I add a background image and change the background colour? Thanks.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/reddit_alien"
android:background="#color/grey"
>
</LinearLayout>
One way to do this, which would be to use 2 layouts.. The outer one having a background of the color and the inner one having the image as the background.
Alternatively you could use a layer list drawable resource file in xml which defines one layer as being the background color and another as the background image. see here: http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
No that's not possible to declare same property twice. Either she them image as background or color.If you want to set the color and background image then create two views. Set the bottom view background to color or image and set the top view background to color or image.
I have implemented slide out navigation using this.
The content should drop shadow near menu list's right edge; like
I'm trying to add shadow by adding a view to content left edge, but it wont show up.
Any clue on how to do this will be appreciated.
Guys I know I am late to the party but i had a hard time finding an answer to this issue that was satisfactory to me so i just wanted to share my solution to this. Fist, create a drawable navbar_shadow.xml and put it with the rest of your drawables. All it is, is a rectangle with a transparent gradient.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#111"
android:endColor="#00000000">
</gradient>
<size
android:height="#dimen/activity_vertical_margin"
android:width="5dp">
</size>
</shape>
Then, wherever you are instantiating your drawer, use your DrawerLayout variable to attach it to your drawer.
mDrawerLayout.setDrawerShadow(R.drawable.navbar_shadow, Gravity.LEFT);
Bam. No need to draw line by line or include any extra resources. You can use your own startColor to match your drawer color, but endColor should remain #00000000 as it is a transparent black.
I know this post is quite old but I had trouble finding a solution so I thought it might help somebody if I posted mine here.
I wanted to add a fade to black on the right had side of this simple ListView.
<ListView
android:id="#+id/sideMenuList"
android:layout_width="300dp"
android:layout_height="match_parent"/>
Created a PNG file with a gradient using GIMP. Add it to /res/drawable. Mine was named fade_from_right.png
Surrounded the ListView with a RelativeLayout. Give the RelativeLayout the background color you want your ListView to have.
Add another View to the right of your ListView. Set the new views background to be your 'fade_from_right.png'
Thats it.
<RelativeLayout
android:layout_height="match_parent"
android:layout_width="300dp"
android:background="#color/solarized_base02">
<ListView
android:id="#+id/sideMenuList"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:layout_alignRight="#id/sideMenuList"
android:layout_width="5dp"
android:layout_height="match_parent"
android:background="#drawable/fade_from_right"/>
</RelativeLayout>
what is the need to add another view with the listview, it will not be perfect i think.. You may try like this right?
sm = getSlidingMenu();
sm.setShadowDrawable(R.drawable.shadowbar);
since we may set some behindView width and offset. this option will give a good look i think.
Hi
in my app contain a Button ,currently i customized using xml for changing the background and it work fine in 2.1 but when am reach to 2.2 ,The button is hard to hit ,how can i solve the issue?
my button xml code given below
<Button
android:id ="#+id/Button_Continue1"
android:background="#drawable/continue_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
/>
If your button is small and hard to hit use an Inset Drawable. You set the drawable you want to have displayed and the inset on the left, top, right and bottom. The inset is like some kind of margin but clickable.
Here is an example.
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="#drawable/your_drawable"
android:insetTop="10dp"
android:insetRight="10dp"
android:insetBottom="10dp"
android:insetLeft="10dp"/>
That will make your button to be 10dp taller on every side for touch events. The look of your button will not change.
Now in your layout you don't set your original drawable as the Button's background anymore but the new Inset Drawable.
Is it possible to have overlapping views in Android? I would like to have an ImageView with a transparent png in the front and another view in the background.
edit:
This is what I have at the moment, the problem is that the image in the imageView is not transparent, the parts that should be transparent are just black.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/gallerylayout"
>
<Gallery android:id="#+id/overview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView android:id="#+id/navigmaske"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/navigmask"
/>
</RelativeLayout>
edit:
I got it to work, it was a theme file from another programmer on the team.
Just changed this
<item name="android:background">#FF000000</item>
to this
<item name="android:background">#00000000</item>
Android handles transparency across views and drawables (including PNG images) natively, so the scenario you describe (a partially transparent ImageView in front of a Gallery) is certainly possible.
If you're having problems it may be related to either the layout or your image. I've replicated the layout you describe and successfully achieved the effect you're after. Here's the exact layout I used.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallerylayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery
android:id="#+id/overview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ImageView
android:id="#+id/navigmaske"
android:background="#0000"
android:src="#drawable/navigmask"
android:scaleType="fitXY"
android:layout_alignTop="#id/overview"
android:layout_alignBottom="#id/overview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</RelativeLayout>
Note that I've changed the parent RelativeLayout to a height and width of fill_parent as is generally what you want for a main Activity. Then I've aligned the top and bottom of the ImageView to the top and bottom of the Gallery to ensure it's centered in front of it.
I've also explicitly set the background of the ImageView to be transparent.
As for the image drawable itself, if you put the PNG file somewhere for me to look at I can use it in my project and see if it's responsible.
Also, take a look at FrameLayout, that's how the Camera's Gallery application implements the Zoom buttons overlay.
If you want to add your custom Overlay screen on Layout, you can create a Custom Linear Layout and get control of drawing and key events. You can my tutorial- Overlay on Android Layout-
http://prasanta-paul.blogspot.com/2010/08/overlay-on-android-layout.html
The simples way arround is to put -40dp margin at the buttom of the top imageview
A visible gallery changes visibility which is how you get the gallery over other view overlaps. the Home sample app has some good examples of this technique.
Now with Jetpack Compose in android, you should use Box for overlapping views.
Example.
Box(modifier = Modifier.fillMaxWidth().fillMaxHeight()){
RecipesList(viewModel.recipes.value)
Snackbar()
}
Here RecipesList and Snackbar are composabes positioned one on top of the other in the composition order
Check out this for Jetpack Compose samples - https://androidlearnersite.wordpress.com/2021/08/03/jetpack-compose-1-0-0-sample-codes/
Yes, that is possible. The challenge, however, is to do their layout properly. The easiest way to do it would be to have an AbsoluteLayout and then put the two images where you want them to be. You don't need to do anything special for the transparent png except having it added later to the layout.