I have used the dependencies to be used as suggested. below is the pic.
build_gradle(module)
now I have selected a black plus icon from vector assets and named it as fab_plus, now I have this file in my drawable folder.
fab_plus_XML
now I tried to used that fab_plus_XML like this. Pic below.
activity_main
Now my question is why is the fab_plus is showing in red.
thanks in advance. pls, help me, someone.
There are two things wrong with the way you are specifying the drawable. To refer to a drawable within your project, you simply use #drawable/your_drawable and to allow backward compatibility of VectorDrawables you should use app:srcCompat as per the guidance.
So in your ImageView, instead of
android:src="#android:drawable/fab_plus"
you should have
app:srcCompat="#drawable/fab_plus"
You will also need to make sure the app namespace is included at the top of your layout xmlns:app="http://schemas.android.com/apk/res-auto" along with the current android and tools namespaces.
you need to use:
app:srcCompat
instead of
android:src
but the tooltip there should exactly tell you this and AFAIR even offer a quick-fix
Related
I am using a Translucent AppCompatActivity, and in the layout of that activity I am trying to use an ImageView. I am putting the src of the image by using the srcCompat tag. I do the see the image on the design view of the Xml file, but not able to see that being rendered on the phone screen.
Thanking in advanced.
First try using the Layout Inspector tool to verify that your ImageView has at least its width and height well defined. Go to Android Studio->Tools->Layout Inspector and analyze your layout.
https://developer.android.com/studio/debug/layout-inspector?hl=en
You need to add vectorDrawables.useSupportLibrary = true inside your Gradle file if it not there. Browse to this https://developer.android.com/guide/topics/graphics/vector-drawable-resources you can find more data here. If it is not resolved by adding this, you can use android:src attribute instead of srcCompact
i want to set the below xml code programmatically. i know about textView.setBackgroundResource(R.drawable...) but i am not able to set textView background to #android:drawable/dialog_holo_light_frame. Please suggest me suitable method.
android:background="#android:drawable/dialog_holo_light_frame"
Try to use the pattern of the code below:
textView.setBackgroundResource(android.R.drawable.dialog_holo_light_frame);
If you want to use and of the standard android resources you have to use android.R. folder rather than just R. . R. is for your own project. So do it like below -
textView.setBackgroundResource(android.R.drawable.dialog_holo_light_frame);
You can do like below:
yourTextView.setBackgroundResource(android.R.drawable.dialog_holo_light_frame);
Problem
I want to override a layout file from android namespace, e.g. R.layout.popup_menu_item_layout (which is referenced from code as com.android.internal.R.layout.popup_menu_item_layout). By saying override, I assume declaring an xml file in the project which would be prioritized over the layout that framework owns.
Note, this is just an example layout, so the question concerns to each layout that's present in sdk/platforms/android-XX/data/res/layout directory.
What I've tried
tools:override
There's an undocumented tools:override tag available, which overrides specific resources. See this answer for an example, which overrides values from Design Support Library, not from Android framework.
Applying tools:override="true" to the root tag of the layout won't take effect.
XML layout references - refs.xml
As described in this post, declaring a refs.xml file in /values/ directory with following content:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item type="layout" name="activity_main">#layout/activity_second</item>
</resources>
will refer to activity_second.xml once activity_main.xml is used. There's an answer that suggests using this technique in order to substitute Snackbar's layout.
This also won't take effect.
Question
Is there any legitimate way to override/substitute a layout file from android package?
I know this is an old question but I also wanted to override a library layout with my own, here's how I did it.
The layout in question was called design_bottom_navigation_item
In refs.xml I added the following:
<resources xmlns:tools="http://schemas.android.com/tools">
<item name="design_bottom_navigation_item" type="layout" tools:override="true">#layout/bottom_navigation_item</item>
</resources>
There are 4 parts to this which I'll explain.
Name: This is the name of the layout you want to override
Type: The type of resource you are trying to override, in this case a layout.
tools:override: This is how you tell Android Studio to override the library layout with your own.
Value: This is where you specify what resource you want to use instead.
You can do this with any resource type this way.
What is that you're trying to do?
If the idea to only replace how the menu-item will look like, you can try the following:
Create a custom MyMenuAdapter extends MenuAdapter
Override the getView method to return the view from your adapter.
You are trying to customise your sdk on the application itself, at runtime.
That's just not how it works.
If you use an SDK on your project(on any technologies), and you need to modify some behavior, you will tweak this SDK and after that, compile your project with this news customized version.
Trying to modify it at runtime is not a good idea.
You will face multiple issues (retro compatibility, security trigger, TREBLE incompatibility , dependency issue, etc)
You have 4 possibilities to do what you want:
Make your own android rom where you will apply your modification
Copy the resources you need to modify on a fake xmlObject with the tag, after the onPostCreate of your application, you will be able to modify the when inflation. You can generalize this behavior and it will simulate an sdk overlay.
Make your own sdk :)
Multi-level reflection, but, no way you succeed with a stable version
Of course, none of this solutions is applicable for a public app.
don't know your issue have fixed or not but simple solution for this is create new layout that is same layout name of framework (in this case is popup_menu_item_layout). Then go to android google source to copy xml content popup_menu_item_layout
So you can custom anything u want. But remember don't change any id of views.
I am using this library from Chris Banes (I will never thank this man enough). It has two different behaviors depending on the android version. I want to get rid of the graphical hint on the PullToRefresListView (circled in the image below) that is shown only on devices with android lower than 4.0.
Does anybody knows how to do it?
SOLUTION:
for anybody in the future searching for the same solution here it is: in the PullToRefreshAdapterViewBase class change getShowIndicatorInternal method from this:
private boolean getShowIndicatorInternal() {
return mShowIndicator && isPullToRefreshEnabled();
}
to this:
private boolean getShowIndicatorInternal() {
return false;
}
If you use a layout XML file, you can also specify ptr:ptrShowIndicator="false" inside the PullToRefreshView's declaration. For example:
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/pullToRefreshListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
ptr:ptrShowIndicator="false" >
</com.handmark.pulltorefresh.library.PullToRefreshListView>
For other attributes, you can refer to /res/values/attrs.xml in the library, which is self-documented.
You may also find the sample project worth looking at.
Quick and dirty- Simply replace the image file for arrow hint with a transparent image in res folder of library.
I'd say try to see if you can adjust the code to simply take it out.
I don't know if there are any methods added to do this for you, but if there are they should be easy to find.
Scrolling through the code a bit quickly, this might be something;
https://github.com/chrisbanes/Android-PullToRefresh/blob/master/library/src/com/handmark/pulltorefresh/library/internal/IndicatorLayout.java
Although i'm not sure if this is actually that arrow, since it doesn't show any hints in this class about being version-based.
I am specifically looking for the drawable android.R.id.empty.
Does any one have an idea what the source path of that default Android drawable is?
The file where it is defined is located in
YOUR_SKD_DIRECTORY/platforms/A_PLATFORM/data/res/values/ids.xml
It is not a drawable but an id as you can clearly see from android.R.id.empty.
This id is meant to be set on a View which should be displayed in case your ListView is empty.
I stumpled upon a really nice guide for Froyo drawables. And don't forget to use android.R.drawables for your integer id. http://androiddrawableexplorer.appspot.com/