Hi
First of all,
I followed this steps
1) I made an activity class and a customized button class which
inherits Button class
2) I made an attrs.xml(in res/values) I declare the custom xml
parameters for my customButton
Here is a code :
================================
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<declare-styleable name="MyImageButton">
</declare-styleable>
<attr name="Focused"/>
<attr name="NotFocused"/>
</resources>
================================
3) in customized-Button class I implement a constructor which inflate
the view based on the xml parameters and retrieve the custom
parameter,
4) and in layout I use the custom parameter as
"app:<custom_parameter>="..."
Here is a code
================================
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/
android"
xmlns:app="http://schemas.android.com/apk/res/
com.android.demo.componentdemo"
<com.android.demo.componentdemo.MyImageButton
android:id="@+id/image_button"
android:src="@drawable/help"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5px"
app:NotFocused="@drawable/help" <===Here!!!!!!!!!!!
app:Focused="@drawable/help_focused"
/>
</LinearLayout>
================================
And I checked R.java file out and there was "attr" and "styleable" as
I expected.
5) In the customized-Button class I made init method for getting
AttributeSet (of course I got attributeset from constructor)
Here is init code
================================
private void init(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.MyImageButton);
=== If you see ApiDemo there is a LabelView there is a this code
CharSequence s = a.getString(R.styleable.LabelView_text);
=============================================
But I can't find anything like R.styleable.MyImageButton_focused
just there is a R.styleable.MyImageButton
did i miss some code in Xml or somewhere else ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---