Programming with eclipse, not recognizing my android code in XML - android

I'm brand new to eclipse and programming and I'm following video tutorials but I can't figure out why my eclipse doesn't recognizing the coding. In the video I see that he adds
android:gravity=center
android:background="#color/red"
and it changes color but mine does not..
the android:gravity changes to a pink color and the =... changes to blue but mine stays black and when I look at the graphic layout the code is not registering
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
android:gravity=center
android:background="#color/red"
<TextView
android:layout_height="wrap_content"
android:text="#string/red" android:layout_width="wrap_content"/>
</LinearLayout>

Here is the corrected Code,
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#ff0000"
>
<TextView
android:layout_height="wrap_content"
android:text="#string/red"
android:layout_width="wrap_content"
/>
</LinearLayout>
Color can be also defined in XML files.
Create a new xml file name color.xml inside /res/values.
Paste the following code inside
<color name="red">#FF0000</color>
Also Make sure you have the following line in strings.xml
<string name="red">Your text</string>
and change the code as follows.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#color/red"
>
<TextView
android:layout_height="wrap_content"
android:text="#string/red"
android:layout_width="wrap_content"
/>
</LinearLayout>

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
-----------------
android:gravity=center
android:background="#color/red"
-----------------
That bit is wrong. It has be declared inside the layout object. Remove it.
<TextView
android:layout_height="wrap_content"
android:text="#string/red" android:layout_width="wrap_content"/>
</LinearLayout>
Have you declared the color red in your resource folder under string xml file?
Read

Missing the quotes in android:gravity="center"
You need to create a color resource: <color name="red">#FF0000</color>
You can find the documentation for the color resource here: http://developer.android.com/guide/topics/resources/more-resources.html

Related

How can I remove the border of a TextView item in a ListView

I have this bank info list for user to select a bank. I have set textview's background with a drawable file to replace system effect. However, it will show orange borders(system effect) around textview which looks terrible for me .I would like to give you guys some pictures, since my reputation is not enough, I'm really sorry about that.
here is my xml file of listview's item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp" >
<ImageView
android:layout_marginLeft="20dp"
android:layout_marginRight="35dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bank_name"
android:background="#drawable/divider_line" />
<TextView
android:id="#+id/bank_name"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:text="bank"
android:textColor="#454545"
android:textSize="16sp"
android:background="#drawable/color_talk_item" />
</RelativeLayout>
here is the drawable file:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="#color/pressed"/>
<item android:drawable="#color/nomal"/>
</selector>
I've also tried to set android:listSelector="#null"in my listview. But it seems not work. Any suggestion is appreciated.
Edit:
I think I've got 2 upvote for not have any picture or miss something.
here is the link of the problem pciture.
https://plus.google.com/photos/106086983193067474741/albums/6152765738463306577
Here is the main listview:
<FrameLayout
android:id="#+id/no_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/rl_title" >
<ListView
android:id="#+id/bank_list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="#00000000"
android:divider="#null"
android:listSelector="#null"
android:fadingEdge="none"
android:scrollingCache="false" >
</ListView>
</frameLayout>
If you want to set listselector null you can do it like below :
in xml android:listSelector="#00000000"
through coding : myListView.setSelector(new ColorDrawable(0x0));

Error- No resource found that matches the given name (at 'MvxItemTemplate' with value '#layout/itemc')

I am using MvvmCross to create PCL.In my Android application,I have created a mvx.mvxListView which has ItemTemplate named itemc.axml.
The file itemc.axml is created in Layout folder but still it gives this error.
Error- No resource found that matches the given name (at 'MvxItemTemplate' with value '#layout/itemc')
Why?
My FirstView.axml file is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res/constD.Droid"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Show Constituencies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/button1" />
<Mvx.MvxListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
local:MvxBind="ItemsSource Result"
local:MvxItemTemplate="#layout/itemc" />
</LinearLayout>
and my itemc.axml file is as follows.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
local:MvxBind="Text name" />
</LinearLayout>
Why it is so?
Try Renaming the file itemc.axml to Itemc.axml, see if that works
I was getting this error when naming in camelCase. renaming to lowercase fixed it.

attribute is missing the android specific namespace

Here is the snippet of main.xml.Although android:layout_width is used its giving attribute is missing.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView android:id="#+id/eventlabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:layout_weight="1"
android:paddingBottom="10px"/>
</LinearLayout>
Could someone point out the mistake?Thanks
You have:
<LinearLayout xmlns="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools
Change it to:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<!-- rest is the same -->
You only had xmlns=... and didn't actually specify the android part of it. Also, your tools XMLNS was missing a closing "
Try cleaning your solution and then build it again.

layout_below item inside included layout

I'm trying to figure out a way to align an item in a layout in respect to an item within an included layout.
Here's a visual representation:
And here is example code that I'm looking for (which obviously doesn't work):
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/info" />
//This would be the dark grey box
<RelativeLayout
android:layout_below="#id/item1">
</RelativeLayout>
</RelativeLayout>
included.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dp">
<ImageView
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:paddingLeft="100dp"/>
</RelativeLayout>
I'm assuming the best way to accomplish this would be through dynamically positioning the dark grey box in code, but I have no idea where to start. Any help would be awesome.
Can you make this below your include? Something like this (instead item1 use info):
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/info" />
//This would be the dark grey box
<RelativeLayout
android:layout_below="#id/info">
</RelativeLayout>
</RelativeLayout>

how to add background image to activity?

using theme or ImageView ?
use the android:background attribute in your xml. Easiest way if you want to apply it to a whole activity is to put it in the root of your layout. So if you have a RelativeLayout as the start of your xml, put it in here:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootRL"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
</RelativeLayout>
You can set the "background image" to an activity by setting android:background xml attributes as followings:
(Here, for example, Take a LinearLayout for an activity and setting a background image for the layout(i.e. indirectly to an activity))
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/icon">
</LinearLayout>
Place the Image in the folder drawable. drawable folder is in res. drawable have 5 variants
drawable-hdpi
drawable-ldpi
drawable-mdpi
drawable-xhdpi
drawable-xxhdpi
We can easily place the background image in PercentFrameLayout using the ImageView. We have to set the scaleType attribute value="fitXY" and in the foreground we can also display other view's like textview or button.
<android.support.percent.PercentFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
>
<ImageView
android:src="#drawable/logo"
android:id="#+id/im1"
android:scaleType="fitXY"
android:layout_height="match_parent"
android:layout_width="match_parent"/>
<EditText android:layout_gravity="center_horizontal"
android:hint="Enter Username"
android:id="#+id/et1"
android:layout_height="wrap_content"
app:layout_widthPercent="50%"
app:layout_marginTopPercent="30%"
/>
<Button
android:layout_gravity="center_horizontal"
android:text="Login"
android:id="#+id/b1"
android:layout_height="wrap_content"
app:layout_widthPercent="50%"
app:layout_marginTopPercent="40%"/>
</android.support.percent.PercentFrameLayout>
ez way : copy your picture in this location: C:\Users\Your user name\AndroidStudioProjects\yourProjectName\app\src\main\res\drawable
and write this code in your xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/background">
</RelativeLayout>
in line 7 write your file name instand of background
and Tamam...
Nowadays we have to use match_parent :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/background">
</RelativeLayout>
and dont forget to clean your project after writing these lines you`ll a get an error in your xml file until you´ve cleaned your project in eclipse: Project->Clean...

Categories

Resources