Adding background to ImageButton Android - android-studio

I have an issue which displays:
Error:(19, 29) No resource found that matches the given name
(at 'background' with value '#drawable/unpressed').
Error:Execution failed for task ':app:processDebugResources'.
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'Drive:\Users\...\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1
Basically I want to add background to an ImageButton which will change after OnTouch() Event. For that first of all, I have to add an Image (a simple scenario without an Event)
I am facing the above mentioned problem in a simple case. I don't know what mistake am I making. My code for ImageButton is:
<ImageButton
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/imageButton"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="202dp"
android:background="#drawable/unpressed"
/>
I have tried all of the solutions searched including:
Clean Solution
Rebuild Solution
Update SDK (mentioned in STACK Solution) Libraries
File > Invalidate Caches/Restart
After pasting image in drawable, synchronized it.
As iGoda informed in the Comments. How can I find where the R settings exactly are changed?

After a long time, the problem solved by:
deleting the files in the path:
C:\Users\UserName\AppData\Local\Temp
If any of the folder in above path is not visible to you, kindly show the hidden files by going into the following Options in the menu bar of Windows Explorer: Organize -> Folder and Search Options(For Windows-7)
Restart system and then check. It will all be fine.

Related

What is the name of this sliding selection list?

I want to implement this type of sliding selection list in my kotlin based android studio app. but, I don't know what actually it is. so, plz help me
Its Called Spinner
In Xml File implement like this
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
Follow this link for more details
https://www.geeksforgeeks.org/spinner-in-kotlin/

How to get rid of the warning "cannot resolve symbole 'id/andr'" for ExpandableListView"

An app uses ExpandableListActivity, and the usage of ExpandableListView is standard based on the document:
<ExpandableListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:divider="#android:color/transparent"
android:dividerHeight="5dip"
android:layout_marginTop="10dip">
</ExpandableListView>
Android Studio 3.2 has the following warning:
How can I get rid of the warning?
This is probably a typo. Change it to:
"#android:id/empty"
and
"#android:id/list"
See also https://developer.android.com/reference/android/app/ListActivity
ListActivity has a default layout that consists of a single,
full-screen list in the center of the screen. However, if you desire,
you can customize the screen layout by setting your own view layout
with setContentView() in onCreate(). To do this, your own view MUST
contain a ListView object with the id "#android:id/list" (or R.id.list
if it's in code)
I don't know what is ( id="#id/android:list")
give it an normal id ( #+id/androidlist )
and handle it in your code
but if you learn how to work with ExpandableListView
I prefer this link tutorial for you ExpandableListView Link
GL sir

Override of Resources in library project

im having a library project which has a Default Fragment implementation. I also added some template methods where the Main Project can hook in and return another Layout Resource ID to be inflated. The Problem i get is that the Runtime sees duplicated IDs. I wonder how this can be avoided ?
#IdRes
#Override
public int getDrawerLayoutResID() {
return R.id.drawerLayout;
}
#LayoutRes
#Override
public int getLayoutResID() {
return R.layout.master_detail;
}
Lib Project:
BaseFragment
layout.xml
Main Project:
ConcreteFragment
layout.xml
I only know this problem from nested Fragments. But im not using any nested Fragments.
I checked the generated R files, both contain the same ID for the same IDs (layout and drawer).
AFAIK the resource merger should override resources which having the same name like an layout.xml in the library project.
All i want is some type of customization for the main Project, as most code is backed in the library project. To archive this customization i have an layout file which is part of the Activiy layout:
Library Project file:
<!-- The navigation drawer -->
<fragment
android:name="com.examle.core.ui.fragment.NavigationDrawerFragment"
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="#layout/fragment_navigation" />
Concrete Project file:
<!-- The navigation drawer -->
<fragment
android:name="com.examle.ui.fragment.ConcreteFragment"
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
tools:layout="#layout/fragment_navigation" />
The Runtime fails when i invoke setContentView in the Activity with expection:
Stacktrace:
Caused by: java.lang.IllegalArgumentException: Binary XML file line #45: Duplicate id 0x7f08006d, tag null, or parent id 0x7f08006b with another fragment for com.example.android.fragment.ConcreteFragment
at android.app.Activity.onCreateView(Activity.java:4751)
According to the docs, when the Android Gradle plugin merges two manifest files that declare the same element then it checks their configuration (i.e. their XML tags and attributes) to check whether that they are identical in the two manifests. If they are then gradle keeps only one of them, if they're not then gradle detects a conflict and adds both elements to the manifest.
Since your two fragments are substantially different, gradle is adding both of them to the final app. Then at runtime, android complains that it found two fragments with the same android:id and throws the error that you saw.
To fix this problem you should remove one of the fragment declarations or alternatively make them the same for both app and library.

Android "tools" namespace in layout xml documentation

Per the question here,
What's "tools:context" in Android layout files?
The 'tools' namespace reference (xmlns:tools="http://schemas.android.com/tools") has begun to appear in my layouts recently, and I want to know more. The original post only described the 'tools:context' attribute, but I have also noticed usage of the "tools:listitem" attribute appearing when I have designated a preview layout item for a listview, i.e.
<ListView
android:id="#+id/lvCustomer"
tools:listitem="#layout/customer_list_item" >
</ListView>
Are there more elements?
What brought me to this 'tools' namespace is that I want to be able to have 'preview-only' text (i.e. in a TextView or EditText) when using the layout designer in eclipse.
Currently, I assign the 'text' or 'hint' property for previewing text when arranging my layouts... but then I always have to remember to clear the preview value from within the code.
Ideally, instead of
<string name="preview_customer_name">Billy Bob's Roadhouse Pub</string>
...
<TextView
android:id="#+id/tvCustomerName"
android:text="#string/preview_customer_name"
</TextView>
have a something like:
<TextView
android:id="#+id/tvCustomerName"
tools:previewText="#string/preview_customer_name"
</TextView>
Thanks-
We've just added support for designtime attributes like this in Android Studio 0.2.11. See http://tools.android.com/tips/layout-designtime-attributes for more.
Think of them as design time helpers only.They do not get processed in actual view rendering at run time.
For example you want to set background of some view in your layout design when working on android studio so that you can make clear distinction where that particular view is.So you would normally do that with
android:background="#color/<some-color>"
Now risk is that sometimes we forget to remove that color and it gets shipped in apk.
instead you can do as follows:
tools:background="#color/<some-color>"
These changes will be local to android studio and will never get transferred to apk.
And also check out http://tools.android.com/tech-docs/tools-attributes for more options.
You will find tool attribute when you set object in graphical layout.
Listview (in graphical mode) -> right Click -> Preview List Content -> Choose Layout...
produces:
tools:listitem="#layout/customer_list_item"
See in layout XML below. There are 2 namespace in use "xmlns:android" and "xmlns:tools".
Tools namespace is used when the developer wants to define placeholder content that is only used in preview or in design time. Tools namespace is removed when we compiled the app.
So in the code below, I want to show the placeholder image (image_empty) that will only be visible at design time, and image1 will the actual image that will be shown when the application launch

Monodroid: Programatically add custom controls to a layout with horizontal and vertical centering

I have an ImageView inside a RelativeLayout that I added programmatically (The ImageView is added by code, not the RelativeLayout.)
If I had added the ImageView by XML, I would have done this:
<ImageView
android:id="#+id/login_loadingimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/imagefilename"
android:visibility="invisible"
/>
But now I want this done programtically. How do I get the centering right? I have tried creating RelativeLaout.Parameters but whe I create them using
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(this, null); //[1]
p.AddRule(...);[2]
An exception is thrown at line 1. In addition I wouldn't know how to apply these LayoutParameters on ViewGroup.LayutParameters anyway.
Also, I cannot just make ViewGroup.LayoutParameters because
1. They do not seem to have the Centering (Horizontal and Vertical) elements I need.
2. Every example seems to indicate there is a Constructor that simply takes Layout_Width and Layout_Height as parameters, but there is not.
Before someone says to add a layout first, please tell me how to center the layout in code as well. Thanks.
Please help.
The way to do it is simple:
Create xaml you want of JUST the component - put the file in the layout folder.
Then use the inflating service to inflate the control inside the code you want (make sure to create the LayoutInflator as follows):
LayoutInflater _inflatorservice = (LayoutInflater)this.GetSystemService(Context.LayoutInflaterService);
Then simply call this:
_inflatorservice.Inflate(Resource.Layout.[control], parent);
and Bob is your mother's brother!

Resources