Strange black line under my custom Action Bar - android

I made my custom Action Bar, but there is an ugly underline in under it.
You can see the black line under my green actionBar.
my Action Bar xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="3dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="0dp"
android:layout_marginTop="4dp" >
<ImageButton
android:id="#+id/menuToggleBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:adjustViewBounds="false"
android:background="#null"
android:scaleType="centerInside"
android:src="#drawable/menu_btn" />
<ImageView
android:id="#+id/loadingIconIv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:src="#drawable/flexilogo" />
<ImageButton
android:id="#+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="#null"
android:scaleType="centerInside"
android:src="#drawable/menu_btn"
android:visibility="invisible" />
</LinearLayout>
<View
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6ea541" />
And my code::
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.action_bar);
menuToggleBtn = (ImageButton) actionBar.getCustomView().findViewById(
R.id.menuToggleBtn);
menuToggleBtn.setOnClickListener(this);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
Why is that black line is there ? I would like to get rid of it.
Please help if you can.
E D I T:
I tried to add:
<item name="android:windowContentOverlay">#null</item>.
to my app's style, but it does not work :(

android:layout_height="match_parent" on the LinearLayout tag
Should fix it

It can be a shadow... take a look at Remove shadow below actionbar
To remove it you have to make a style and use <item name="android:windowContentOverlay">#null</item>.

Use the hierarchyviewer perspective in Eclipse ADT and load your activity into it.
Then select different nodes to show their graphical representation.
Try to find the node that includes the black line.
You can also click the approximated spot on the layout-preview in the lower right to select a node that includes this spot.
Then examine the Layout- and Measurement-properties for the selected nodes and neighbouring (sibling) nodes and their graphics preview by right-clicking the node in the tree-view and pressing the box-icon above the small preview.
If you have found the node containing the black line, look at its layout-properties and fix them
If there isn't a node containg the black line for itself, it would likely be a gap in your layout, with the default-background shining through. Then you would have to presumably fix the layout-properties (layout_height) of your main contentview (the one containing the TextView saying "segedanyaok").
Hint:
if your app's activity isn't shown in bold in the Windows-View of the hierarchy-perspective, you need to include the ViewServer-component in your app's activity to enable introspection with hierarchyviewer: https://github.com/romainguy/ViewServer
If the hierarchyviewer-connection gets in trouble (maybe due to timeouts) and is non-responding giving errors, reset the adb-connection to your device from the ddms-perspective, Devices-view, menu-item "Reset adb".
Another hint:
You don't have to use a custom-view to show your logo in such a style. To have a drawer-appliance with a logo, look at how to include Google's navigation drawer http://developer.android.com/design/patterns/navigation-drawer.html and how to include your logo as the actionbar-up/drawer-icon http://developer.android.com/guide/topics/ui/actionbar.html#Logo.

Related

getting rid of extra space that comes with android's default buttons

I've placed three buttons side by side using constraints, with 4dp gap between each as shown below, but due to this "extra space"(shown below), the actual gap between buttons looks greater than it is:
What is the attribute that android uses to maintain this space? How can I remove it. I'm using the default <Button> widget that is android's default button widget.
Add this attribute to the buttonstyle="#style/Widget.AppCompat.Button.Borderless". This will make your button white and borderless. After add background to your button using this. android:background="#android:color/darker_gray"
Your button should be as below.
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
style="#style/Widget.AppCompat.Button.Borderless"
android:background="#android:color/darker_gray"/>
Add Background to your Button and this space will cover by the background color.
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
android:background="#color/colorPrimary"
android:padding="2dp"
android:layout_margin="4dp"/>
You can also use translationX and translationY property.

Items Don't Stay Where Placed With Drag Drop Feature in Android Studio

So Android Studio has the drag/drop feature in the design tab. I am able to place the elements where I want them, and the layout looks great on the screen.
However, when I go to run the app emulator, it looks completely different. Everything gets shoved up to the top-left hand corner of the screen, nowhere near where I placed it in design mode.
Is there a way to have your elements show the same way in the emulator, as the way you place them in design mode? Right now I'm having to go back and edit all the code each time.
I have my code below, as well as a image link below to further clarify my point.Comparison of Design mode vs App Emulator
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.luke.currencyconverter.MainActivity">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter The Amount in Dollars"
tools:layout_editor_absoluteX="-159dp"
tools:layout_editor_absoluteY="126dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="403dp"
android:layout_height="0dp"
android:text="Enter The Amount in Dollars:"
android:textColor="#android:color/black"
android:textSize="22sp"
tools:layout_editor_absoluteX="33dp"
tools:layout_editor_absoluteY="365dp" />
<ImageView
android:id="#+id/currency"
android:layout_width="361dp"
android:layout_height="450dp"
app:srcCompat="#drawable/currency"
tools:layout_editor_absoluteX="12dp"
tools:layout_editor_absoluteY="-117dp" />
<Button
android:id="#+id/convert"
android:layout_width="361dp"
android:layout_height="wrap_content"
android:onClick="convert"
android:text="Convert"
tools:layout_editor_absoluteX="12dp"
tools:layout_editor_absoluteY="462dp" />
<EditText
android:id="#+id/dollarField"
android:layout_width="368dp"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="numberDecimal"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="408dp" />
</android.support.constraint.ConstraintLayout>
Drag and drop for android will only place the object within the screen. To keep it there you should modify the xml so that the objects will be constrained to each other.
You can use either relative layout or constraint layout for an easier time in designing your layout.
I figured it out. I was using "constraint layout", and I needed to use "relative layout".
I just had this error as well and as annoying as it sounds, my solution was to delete my xml file and recreate it.

Prevent Android ActionBar from scrolling

I have 5 tabs in my ActionBar and I've styled them to remove padding and reduce the text size on the tabs, but no matter I do, the tab bar will scroll just a few pixels in either direction. My tabs all fit, so I don't want them to be able to slide back and forth, even if a little bit.
How do I prevent the ActionBar tabs from being scrollable?
I'm using ActionBarSherlock in my project so that I can have a uniform UI across different versions of Android.
As you can see below, there is plenty of space so I don't see any reason it should be able to wiggle/scroll when all of the tabs fit just fine.
There are no secrets, it simply means there are too much tabs in your ActionBarSherlock and/or their width is too big.
here is an exemple of tab layout with an image and a text :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/tab_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="8dp" >
<ImageView
android:id="#+id/tab_icon"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="4dp" />
<TextView
android:id="#+id/tab_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:textColor="#android:color/white"
android:textSize="12sp" />
</LinearLayout>
Are you using a TabAdapter ? maybe you could post your code to see if there is something goin on ?

How to remove button background color

I searched a lot but I didn't find how to remove the background color from the button which is appearing on the right and left side of button. Can anybody help?
My screen looks like
No matter what I try I am not able to remove the black portion.
Code:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_base"
android:text="#string/base"
android:layout_margin="2dp"
android:textColor="#000000"
android:background="#drawable/selector_button"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="30dp"/>
<Button
android:id="#+id/btn_care"
android:text="#string/care"
android:layout_margin="2dp"
android:textColor="#000000"
android:background="#drawable/selector_button"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="30dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/btn_daily_prize"
android:layout_margin="2dp"
android:textColor="#000000"
android:background="#drawable/selector_button"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="30dp"
android:text="#string/daily_prize" />
<Button
android:id="#+id/btn_winner"
android:layout_margin="2dp"
android:textColor="#000000"
android:background="#drawable/selector_button"
android:layout_weight="0.5"
android:layout_width="0dp"
android:layout_height="30dp"
android:text="#string/winner" />
</LinearLayout>
</LinearLayout>
#Drawable/selector_button
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true"
android:drawable="#drawable/pressed"> </item>
<item android:state_focused="true"
android:drawable="#drawable/focused"/>
<item android:drawable="#drawable/change"></item>
</selector>
this is the image used with name change.9.png
according to your scenario i can surely say that either you are not using a 9-patch image (an image with extension like .9.png ) or the 1 pixel borders of 9-patch at left and top are not drawn in correct manner. thats why the edges and the side border shade get expanded with the button with long width. either you should show what 9-patch button background you have used or try some correct 9-patch and check results for that.
Why don't you use some other control element like TextView instead of buttons? I just saw that TextView has onClickListner and so you can use it as sort-of button, though I have not done it; button is meant to aid you defining your layout, but as this seems to only be a problem for you, just do not use it).
By the way I seriously recommend you to use android styles, as you copy-paste a lot of attributes. If you use Eclipse for development, open your layout xml, select the item you want to extract the style of, press ctrl + 1 and then select extract style. That way you should avoid copy-pasting all these style attributes.
Try removing the android:textColor attribute. These can be misleading and sometimes alter the colour of more than just the text. If the text is supposed to be black then you don't need it.

Android: Dialog background on emulator and my phone are different color

This is the dialog on the emulator:
And this is on my phone:
I tried setting background to my layout but then the title space and bottom space would still be this white color. How do I "repair" it?
If it matters, the second picture is from MIUI ROM.
//EDIT:
Here is my layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<Spinner
android:id="#+id/spinner_minutes"
android:layout_width="170dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:entries="#array/timer_values"/>
<TextView
android:id="#+id/text_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone"/>
<LinearLayout
android:id="#+id/button_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_minutes"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip">
<Button
android:id="#+id/button_set"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Set"
android:layout_marginLeft="10dip"
android:layout_marginBottom="5dip" />
<Button
android:id="#+id/button_cancel"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginRight="10dip"
android:layout_marginBottom="5dip" />
</LinearLayout>
<LinearLayout
android:id="#+id/button_holder2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/text_timer"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip"
android:visibility="gone">
<Button
android:id="#+id/button_close"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Close"/>
<Button
android:id="#+id/button_cancel2"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:text="Cancel"/>
</LinearLayout>
</RelativeLayout>
I am creating the dialog this way:
about_dlg=new Dialog(SoundRelaxerActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.about_dialog);
about_dlg.show();
This call:
about_dlg=new Dialog(SoundRelaxerActivity.this);
will use the system default theme. Every hardware manufacture develops their own custom system default themes. For example, the default Button might look different on Motorola Blur than it does on HTC Sense. If you want to build a dialog, with a custom theme, use this call instead:
about_dlg = new Dialog(context, android.R.style.Theme);
BUT android.R.style.Theme might not be what you want. Look at http://developer.android.com/reference/android/R.style.html
and check out any of the values defined as Theme_
AND A HEADS UP:
This might not work out of the box. You are going to have to modify your layout xml file to have the appropriate styles relevant to the theme you choose. For example, Android.R.style.Theme defaults to a solid black background.
And lastly,
this might not be worth the effort. While Android Fragmentation is a pain in the butt, sometimes we have to embrace it. The user is used to the default settings of the device-- for example if every dialogue on their phone is white but yours is black, they might be jarred by this. That is a weak example, but hopefully you get the point.
Make sure you are setting the background of the top overall layout (in this case the relative layout)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#c0c0c0">
The emulator is just using a different default color than your phone. Change #c0c0c0 to whatever color you want
I know on Android 4 you can ask for the default Holo theme for your application which eliminates this possibility as Holo HAS to be present on an Android 4 system. Prior to that, all you've got is the default theme which could be anything at all.
The question is, why is your text white on white on MIUI? Are you setting that explicitly? If you aren't, then I would consider that you're seeing a bug in the theme rather than your app because if the theme author has made these dialogs white then the default text colour should surely be dark or else every app would suffer the same problem.

Categories

Resources