Android Button Alpha looks weird on 2.2 and lower - android

Hello stackoverflowers!
This is my button:
<Button
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.30"
android:text="#string/menu_button_newgame"
android:id="#+id/button_newgame"
/>
when I set it's alpha to 150 with
button_newgame.getBackground().setAlpha(150);
it starts looking weird on 2.2! On 2.3.3 the buttons look normally.
Android 2.3.3: (normal)
Android 2.2: (buggy)
What to do ?? :)

It seems to be a problem with the nine-patch.
Try to use
android:layout_height="wrap_content"
All the buttons has the same content and they should keep the same height.
Or try to create a custom nine-patch drawable to use as background.

Related

Android studio App icons are too close

I am playing around with the smart mirror code and when I build and run the app on a Android TV AVD, the app makes all the info on the screen too close. The app shown in the Github website has is all neat and spread out but mine as shown below is all together.
Is there a setting I forgot to change?
Try to add this line in activity_home.xml to control your textSize
,the example set 30sp, you can set other what you need.
Example
<TextView
android:id="#+id/news_1"
style="#style/NewsStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_marginBottom="#dimen/intra_group_margin"
android:drawableLeft="#drawable/news_ap"
android:drawablePadding="#dimen/icon_margin"
add > android:textSize = "30sp"
tools:text="Obama, Sanders at the White House: Nice chat but that's all"/>

Show error for unsupported custom attribute

I am working on an Android Library, which makes buttons of different shapes. The Button's XML looks like this:
<com.singh.daman.mybutton.ShapedButton
android:id="#+id/round"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:fill_color="#color/colorPrimaryDark"
app:button_type="round_rectangle"
app:stroke_color="#color/colorAccent"
app:stroke_width="12sp"
app:text="Round Rectangle"
app:text_size="16sp"
app:text_color="#ffff"
android:layout_gravity="center"
android:background="#null" />
In which attribute app:button_type="round_rectangle" have different values like rectangle, star, circle and round rectangle.
The type round_rectangle is supported by only Lollipop and Above android versions.
So, When the library user sets button_type to round_rectangle and the app minimum android version is less than Lollipop, I want to show an error that it is only supported by api 21 and above, How can I do that?
You need a custom lint rule. I've never done this, but there are writeups from Google on the topic.
http://tools.android.com/tips/lint-custom-rules

PNG transparent backgrounds appearing black when using Android Studio

The social icons below (for fb, twitter, mail and share) are circular PNGs with transparent backgrounds. When I use the code and exact same images in Eclipse, I get transparent background but when build and run with Android Studio, I get black backgrounds. See details below.
Images are the same. Code used in layout xml files:
<LinearLayout
android:id="#+id/ll_shareBtns"
android:layout_width="#dimen/sharesection_width"
android:layout_height="#dimen/sharesection_height"
android:layout_gravity="center"
android:background="#drawable/bg_sharebox"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/btn_facebook"
android:layout_width="#dimen/dimens_sharebtns"
android:layout_height="#dimen/dimens_sharebtns"
android:layout_marginLeft="#dimen/sharebtns_leftmargin"
android:layout_marginRight="#dimen/sharebtns_rightmargin"
android:background="#drawable/bg_facebookbtn"
android:gravity="center" />
<Button
android:id="#+id/btn_twitter"
android:layout_width="#dimen/dimens_sharebtns"
android:layout_height="#dimen/dimens_sharebtns"
android:layout_marginLeft="#dimen/sharebtns_leftmargin"
android:layout_marginRight="#dimen/sharebtns_rightmargin"
android:background="#drawable/bg_twitterbtn"
android:gravity="center" />
<Button
android:id="#+id/btn_email"
android:layout_width="#dimen/dimens_sharebtns"
android:layout_height="#dimen/dimens_sharebtns"
android:layout_marginLeft="#dimen/sharebtns_leftmargin"
android:layout_marginRight="#dimen/sharebtns_rightmargin"
android:background="#drawable/bg_emailbtn"
android:gravity="center" />
<Button
android:id="#+id/btn_share"
android:layout_width="#dimen/dimens_sharebtns"
android:layout_height="#dimen/dimens_sharebtns"
android:layout_marginLeft="#dimen/sharebtns_leftmargin"
android:layout_marginRight="#dimen/sharebtns_rightmargin"
android:background="#drawable/bg_sharebtn"
android:gravity="center" />
</LinearLayout>
When code compiled and run with Android Studio, I see this:
When code is compiled and run with Eclipse, I see this:
Quite Strange. Could difference in build tools version cause this problem too?
Its seems to be problem in Theme used in xml file .
-check it once if the theme is different in eclipse and Android Studio then you can correct it.
by changing the Theme on file style.xml
Hope this will helpful .thanks
Did you try testing your app in a device? This is a known bug with Android Studio where icon PNGs show a black box despite being transparent. I faced the same issue where I saw a black box background in Android Studio layout design preview but the image rendered correctly in the device.
This link can give you more confidence - ic_stop_white_*dp.png background is black, not transparent

Custom Checkbox Shows Different layouts for 2.3 and 4.2

I am Working on Project with inside i want to Use custome image for Checkbox checked/unchecked event.
inside my login xml i have write :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp" >
<CheckBox
android:id="#+id/chk_remember_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/checkbox_uncheked"
android:paddingLeft="5dp"
android:text="Remember Me"
android:textColor="#024d94"
android:textSize="12dp" />
</LinearLayout>
Here i have Used android:paddingLeft="5dp" for getting space between button and textview.
My Problem : i got two different views for 2.3 and 4.2
for Device that has xhdpi or below density or that has large screen i
am getting below screen (this one is perfect as i want ):
for Device that has hdpi or below density or that has normal/small
screen i am getting below screen :
Can anyone tellme where am i missing? or anything Wrong in my layout?
I want the same layout screen which i am getting for 4.2 device in normal/large screen devices.
Thanks in advance.
It appears that Checkbox already uses padding by default internally and overriding it with paddingLeft causes these issues. You should remove that property from your XML.
If you still want to adjust the padding, you will have to do so programatically. See this answer: https://stackoverflow.com/a/4038195/832776
To only apply it to >4.2 you can use the following, though I would test on emulators to make sure this issue isn't merely a problem with just your devices.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Give the fixed width to check box hopefully this can resolved your problem.
Don't give padding, it comes by default with Checkbox.

Drawable not showing up

I have a fairly simple xml file that has an image button in it. The image shows up fine on the Graphical Layout xml designer, shows up fine when I run a development build, but as soon as I create the signed apk file and run it, the image no longer shows up. It's just an empty button. I can't think of a reason why, any ideas? The xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/navigation_root"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/navigation_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="TextView"
android:textAppearance="?android:attr/textAppearanceLarge" />
<SeekBar
android:id="#+id/navigation_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:padding="5dp" />
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp" >
<ImageButton
android:id="#+id/part_select_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/chapter_select" />
<Button
android:id="#+id/navigation_ok_button"
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/ok" />
<Button
android:id="#+id/navigation_cancel_button"
android:layout_width="75dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="#string/cancel" />
</LinearLayout>
</LinearLayout>
The image #drawable/chapter_select is a fairly small (41*41) png file that is in the res/drawable folder.
Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't show up. Added a dummy image called aaaa.png to the drawable folder and problem was solved. Found the answer here: ImageButton does not display a particular drawable
One of the reason is:
If you are using Vector file as a drawableLeft or drawableRight (or drawableStart or drawableEnd) in layout.xml, then you have to use androidx.appcompat.widget.AppCompatButton (formerly android.support.v7.widget.AppCompatButton) instead of Button.
Simple View like Button or Textview doesn't support Vector file as a drawableLeft or drawableRight (or drawableStart or drawableEnd) in my case.
Had the same issue and resolved it by removing all special characters. In my case it was dashes '-' in the filename:
background-720.png => background.png.
try to put the image in drawable-hdpi and drawable-mdpi folder
depends on what device you run you app , the image is searched in these folders...
But puting in drawable means that the image should be available everywhere, but somethimes (depends on your manifest settings) this could not be true, I mean you can turn of the compatibility mode.
also you can try dinamically at run time to set the image to the view
iv.setImageResource(R.drawable.somethig);
My situation was weird.Everything was correct until integrating FireBase Crash report to my Application.
I just added compile 'com.google.firebase:firebase-crash:11.0.1' & DrawableLeft vanished .When i went through the xml , noticed a warning (In lined below).
So added android:drawableStart & issue gone.
Still I am wondering about the relation of FireBase Crash reporting to the same.
Using left/right instead of start/end attributes Using Gravity#LEFT
and Gravity#RIGHT can lead to problems when a layout is rendered in
locales where text flows from right to left. Use Gravity#START and
Gravity#END instead.
Similarly, in XML gravity and layout_gravity attributes, use start
rather than left. For XML attributes such as paddingLeft and
layout_marginLeft, use paddingStart and layout_marginStart.
NOTE: If your minSdkVersion is less than 17, you should add both the
older left/right attributes as well as the new start/right attributes.
On older platforms, where RTL is not supported and the start/right
attributes are unknown and therefore ignored, you need the older
left/right attributes.
There is a separate lint check which catches that type of error.
(Note: For Gravity#LEFT and Gravity#START, you can use these constants
even when targeting older platforms, because the start bitmask is a
superset of the left bitmask. Therefore, you can use gravity="start"
rather than gravity="left|start".)
Check your image size. If you're using an unnecessarily large asset when actually deployed it might just not show despite looking correct in the designer.
Well ! in my case setting MinifyEnabled false and shrinkResources false is working fine now.
i was getting image from drawable. it was working pretty nice in debug version but after release version of apk it was showing sometime blank ImageView.
minifyEnabled false
shrinkResources true
**
See the Screenshots
**
Hope this may help anyone.
I had a similar problem where a drawable png was not showing up in Android Studio. Deleted the file and added it again in the drawable folder and it Worked for me.

Categories

Resources