When I'm applying style to my button #style/Widget.Material3.Button then it is making the whole layout design disappear and the layout is not visible anymore.
Here is my XML Code.
<Button
style="#style/Widget.Material3.Button"
android:id="#+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="60dp"
android:text="Text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textField" />
Is there any solution to solve this render problem?
For Material style you need to use Material components.
com.google.android.material.button.MaterialButton
Go to themes and change the parent element of your style to:
Recently I got rendering problem too after updating from Android Studio Bumblebee into Android Studio Dolphin version 2021.3.1 patch 1 in the same project (nothing changed, no code changed and suddenly it just error rendering).
I used this style
style="#style/Widget.Material3.Button.Icon"
try the solution listed in this
Failed to find '#attr/shapeAppearanceSmallComponent' in current theme
in my case, I added this line in my theme files, because it caused rendering problem saying that it failed to find attr/textAppearanceLabelLarge in my current theme.
<item name="textAppearanceLabelLarge">#style/TextAppearance.Material3.LabelLarge</item>
So whatever is missing, just fill it in in your theme files.
Related
I have a Material Button (from Google's Material Components) which can cast black shadow normally. But when I change the shadow color, it won't appear at all. Here's the button's XML portion :
<com.google.android.material.button.MaterialButton
android:id="#+id/next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_activity_horizontal"
android:enabled="false"
android:elevation="8dp"
android:layout_margin="16dp"
android:text="#string/setup_next"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/nickname_entry_wrapper"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
tools:enabled="true"
android:textSize="18sp"
android:textColor="#000000"
android:backgroundTint="#FFFFFF"
android:fontFamily="#font/poppins_semibold"
android:paddingVertical="12dp"
android:outlineAmbientShadowColor="#FFFFFFFF"
android:outlineSpotShadowColor="#FFFFFFFF"
android:outlineProvider="background"
android:translationZ="8dp"
/>
As you can see, outlineAmbientShadowColor and outlineSpotShadowColor are supposed to change the shadow color that results from elevation and Z translation, right ? I tried adding both elevation and Z translation at once but nothing works, the button still has 0 shadow.
The button is a child view of a Constraint Layout that has a black background. As you can see, I even tried using different values for outlineProvider such as bounds or paddedBounds, yet..nothing.
If anyone has experience with these outline attributes, I'd love to have this solved. The problem isn't specific to Android 11 only, I am just saying that I am using Android 11 for testing, since those outline attributes are only available on Android versions later than Oreo.
As Mike M. has mentioned in the comment, those attributes don't really change the color, they just add a little 'tint'.
If you wanna use material buttons with more features, you should take a look at this library :
Github Repo: Carbon by ZieIony
It should fulfill the required objective (casting white shadows) successfully and without issues on all Android APIs.
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 am a beginner in android development. I have created a android project. But in the preview section, I am not able to see the components. But components are visible when i run the same app on emulator i am able to see the components. I am missing some setting here? XML is given below.
<?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=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I've had have also this problem and solved it by only selecting another "Theme" cause
the default theme appTheme doesn't show added items.
If you i.e. select Transulcent, any item becomes visible ;-)
cheers
Oliwan
Maybe sound a weird answer, but self-tested this.
Change the XML file's (maybe activity_x.xml) layout's root tag android.support.constraint.ConstraintLayout to LinearLayout, then preview will start working again (as happened in my case). [If not, then perform force refresh (R)]
Then switch back to old one, I mean: Change the XML file's (maybe activity_x.xml) layout's root tag LinearLayout to android.support.constraint.ConstraintLayout. And force a refresh.
This does seem to be a bug in Android Studio. When it showed up for me, I fixed it by making a trivial change in the app build.gradle (change version code), do a gradle sync, then change back and sync again.
After that, the design view worked again.
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
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.