This question is already exist in here. But I want to know this step by step.
I pasted the dependence in gradle under dependencies.
compile 'com.android.support:appcompat-v7:25.3.1'
and than what to do.
My xml code is here
<Button
android:id="#+id/button_not_working"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/imageViewGroup"
android:layout_marginTop="60dp"
android:paddingEnd="9dp"
android:layout_alignStart="#+id/imageViewGroup"
android:layout_alignEnd="#+id/imageViewGroup"
android:background="#drawable/button_background"
android:text="Drawable Tine not working"
android:textColor="#color/white"
android:textSize="#dimen/font_size_small"
android:textAlignment="center"
android:layout_marginBottom="10dp"
android:drawableEnd="#drawable/forword_arrow"
android:drawableTint="#color/white"
android:gravity="center"
/>
this is the picture
The color of the forward_arrow is not changing.
There are several answer in here but want to know what to do step by step.
That's it.
Tinting compound drawables in TextView (and their descendants such as Button) was introduced in API 23 (Android 6) via android:drawableTint and android:drawableTintMode attributes.
As of today this feature was not yet backported to AppCompat support library.
Naturally I took an attempt at solving this myself. Check out the appcompat-extra library. It has the XpAppCompatTextView and XpAppCompatButton widgets. Your code may look like this:
<android.support.v7.widget.XpAppCompatButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Drawable tint working"
android:drawablePadding="8dp"
app:drawableEnd="#drawable/forword_arrow"
app:drawableTint="?android:textColorPrimary"/>
Note that android:drawablePadding still uses the android prefix.
Layout preview of this widget may be broken. In such case add the following code so you at least know what the result app will look like:
tools:drawableEnd="#drawable/forword_arrow"
tools:drawableTint="?android:textColorPrimary"
To get the library put this in your app module build.gradle:
repositories {
maven { url 'https://dl.bintray.com/consp1racy/maven/' }
}
dependencies {
compile 'net.xpece.android:appcompat-extra:1.2.0'
}
You have to use the tint atttibute
EDIT: My mistake, it should be backgroundTint
Related
My android sudio design editor don't render material TextInputLayouts. I already tried invalidate caches. Every other element is rendering correct also other material elements
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/ti"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="20dp"
android:hint="#string/street_number">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="text"
android:text="#{vm.user.streetnumber}" />
</com.google.android.material.textfield.TextInputLayout>
You have to change in build.gradle
implementation 'com.google.android.material:material:1.2.0-alpha02'
It seems newer versions are not rendered correctly.
See:how to solve render problem Path.op() not supported?
You need to change the theme in the layout builder to match the one of your app.
in my case Update Android Studio, problem fix
Show all warnings in XML and press to recommendation that wrapped with blue and press modern rendering feature and Restart Android Studio. You can switch off this feature.
I will being by saying that I have seen SOME answers for this question on stackoverflow already, but only providing a quick 'fix' solution. I would like, if possible, to also understand WHY this is happening (an answer with some detailing).
Now to get to the question: I have just re-started android development, using Android Studio 2.2 . I have an ios app which I want to port to android (meaning, recreate it for Android). I have started with a basic template from Android Studio, added a Constraint Layout and 2 ImageViews using 2 PNG files that I have copied in DRAWABLE folder.
Without making any changes or whatsoever , when I try to build I get this error:
Error:(11) No resource identifier found for attribute 'srcCompat' in package 'x.y.z'. This happens for both images. Here is the layout file:
<?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/lib/x.y.z"
xmlns:app2="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="x.y.z.MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app2:srcCompat="#drawable/pngFile1"
android:id="#+id/imageView"
app2:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="8dp"
app2:layout_constraintRight_toRightOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginRight="8dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app2:srcCompat="#drawable/pngFile2"
android:id="#+id/imageView2"
app2:layout_constraintBottom_toTopOf="#+id/imageView"
app2:layout_constraintRight_toRightOf="#+id/imageView"
android:layout_marginBottom="8dp" />
Now, here are some things that I would like to understand, in order to have a proper answer to my question:
some of the other answers I have found on SO propose to change the default:
xmlns:app="http://schemas.android.com/apk/res-auto"
to:
xmlns:app="http://schemas.android.com/apk/lib/x.y.z"
It's true that this removes the error from the build, but what seems strange to me (with my little-to-none android experience), is that Android Studio creates then another similar line when i add the 2nd image:
xmlns:app2="http://schemas.android.com/apk/res-auto"
And as we can see, it uses this for the images, so the errors appear again.
I remember like one year ago i had worked on an app on Android Studio, and have used almost the same way of adding images / buttons with images and these problems were not there.
That's why I would also like to understand why this is happening and how to fix it properly.
Thanks in advance !
Fist of all you need to concentrate on the version of android studio you are using. You should also look at the minSdkVersion and targetSdkVersion.
Try to use android:src="" instead of app2:srcCompat=
app2:srcCompat= suports older APIs when loading vectorDrawable.
If you want to use it,then amend your build.gradile like,
android {
defaultConfig {
vectorDrawables.useSupportLibrary = true
}
}
For more information you can refer to this link
or you can refer to this answer at stackoverflow
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_alignParentStart="true"
android:layout_alignParentEnd="true"
android:background="#drawable/cooltext201199220690445" />
I just changed mine into like this and it worked for me
I just removed that srccompat and replace it with "background"
and i completely removed "xmlns:app2="http://schemas.android.com/apk/res-auto" hope this helps you :)
Is there any standard tools or existing libraries to create a circle button like on Gmail App?
In the android support design support library one of the widgets provided is the Floating Action Button, which is usually added in the bottom right corner(but need not be used only there)
A floating action button is a round button denoting a primary action
on your interface. The Design library’s FloatingActionButton gives you
a single consistent implementation, by default colored using the
colorAccent from your theme.
To get the android design support library in your build.gradle file, add this:
compile 'com.android.support:design:22.2.0'
In your layout file"
<RelativeLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.FloatingActionButton
android:id="#+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_anchor="#id/appbar"
app:layout_anchorGravity="bottom|right|end"
android:src="#drawable/ic_discuss"
android:layout_margin="10dp"
android:clickable="true"/>
</RelativeLayout>
Details of android design support library here
Also there are many other libraries providing the FAB like
https://github.com/makovkastar/FloatingActionButton
https://github.com/futuresimple/android-floating-action-button
1.First important thing use Android Studio
2.Add as a dependency to your build.gradle:
dependencies {
compile 'com.melnykov:floatingactionbutton:1.3.0'
}
3. Create a layout
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.melnykov.fab.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:src="#drawable/ic_action_content_new"
fab:fab_colorNormal="#color/primary"
fab:fab_colorPressed="#color/primary_pressed"
fab:fab_colorRipple="#color/ripple" />
4.Add the namespace
xmlns:fab="http://schemas.android.com/apk/res-auto"
to your layout file.
You can also Set the button type (normal or mini) via the fab_type xml attribute (default is normal):
fab:fab_type="mini"
or
fab.setType(FloatingActionButton.TYPE_MINI);
Yes, with the new Design Support Library a default implementation of the floating action button is provided here.
In order to have access to the new FAB class you will need to add this dependency to your gradle build file.
compile 'com.android.support:design:22.2.0'
The default Facebook LoginButton object and the Google SignIn button object have completely different appearances and they do not fit in my existing layout together. To my knowledge, these objects are not assets I can modify without changing the library itself (where I would assume these components are also open source)
How do people deal with this? I have seen apps that have sign-in options for both of those that use their own custom buttons, but in my implementation I am using those given objects that automatically call their respective libraries on click.
I can of course dive deeper, but I feel like I am reinventing the not-so-obvious wheel if I did that
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
This object is not so obviously a button, and I haven't yet inspected to see if it really is a button.
I need to use different assets for both the Google+ and Facebook Login button.
What I have
An android example I like (Duolingo app)
edit:
after some very simple layout adjustments, this is the result (in landscape mode, just to illuminate the problem)
these buttons are still very different and I need a different asset that will still access the correct methods. I sort of get how to do it with Facebook, thanks to the examples, but Google sign in is pretty cryptic to me right now
To change the text on the Facebook button use:
fb:login_text="Put your login text here"
fb:logout_text="Put your logout text here"
You will also need to add this to the button:
xmlns:fb="http://schemas.android.com/apk/res-auto"
like so:
<com.facebook.widget.LoginButton
xmlns:fb="http://schemas.android.com/apk/res-auto"
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="0dp"
fb:login_text="Sign in with Facebook"
/>
Try This :
Add this method to your activity:
protected void setGooglePlusButtonText(SignInButton signInButton, String buttonText) {
for (int i = 0; i < signInButton.getChildCount(); i++) {
View v = signInButton.getChildAt(i);
if (v instanceof TextView) {
TextView tv = (TextView) v;
tv.setTextSize(15);
tv.setTypeface(null, Typeface.NORMAL);
tv.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
tv.setText(buttonText);
return;
}
}
}
Add following line in onCreateMethod
(where you have init the id's) :
setGooglePlusButtonText(btnSignIn, getString(R.string.common_signin_button_text_long));
The buttons are not styled in exactly the same way - different curve on the corners and use of drop shadows. So its not possible to make them look exactly the same. The closest I could get was to make a vertical linear layout with a precise width of 215dip - and set the width of the buttons to be match_parent:
This used the following layout.xml:
<LinearLayout
android:layout_width="215dip"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="vertical" >
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.facebook.widget.LoginButton
android:id="#+id/authButton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
With the Google+ button, you can simply use your own asset - com.google.android.gms.common.SignInButton behaves the same as android.widget.Button and you register an onClick handler in the normal way. Just be sure to follow Google's branding guidelines when you create your asset:
https://developers.google.com/+/branding-guidelines
Note however that Google+ button does provide translations which you will need to create yourself if you implement your own button in several languages.
With the latest sdk, both the buttons looks similar. The code and results are mentioned below.
Step 1: build.gradle
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.google.android.gms:play-services:7.5.0'
Step 2: myActivity.xml
<com.google.android.gms.common.SignInButton
android:id="#+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<com.facebook.login.widget.LoginButton
android:id="#+id/login_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"/>
Step 3: Result
Step 4: Updated build.gradle with latest gcm
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
compile 'com.google.android.gms:play-services:8.4.0'
Step 5: Result
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.