android - Custom action bar -
i created layout custom action bar:
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/contacts_action_bar" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="#835ca1" android:padding="1dip" > <!-- listrow left side thumbnail image --> <linearlayout android:id="@+id/thumbnail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginright="5dip" android:padding="3dip" android:layout_centervertical="true" > <imageview android:id="@+id/home_image" android:contentdescription="@string/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/cantacts_icon_action_bar" /> </linearlayout> <linearlayout android:id="@+id/thumbnaill" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@+id/thumbnail" android:orientation="vertical" > <textview android:id="@+id/contactname" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="4dip" android:textcolor="#ffffff" android:textsize="14sp" android:typeface="sans" android:text="super mario" /> <textview android:id="@+id/onlineoroffline" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="4dip" android:textcolor="#e876af" android:textsize="12sp" android:typeface="sans" android:text="online" /> </linearlayout> <linearlayout android:id="@+id/thumbnail_edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_marginright="5dip" android:padding="3dip" android:layout_centervertical="true" > <imageview android:id="@+id/edit_image" android:contentdescription="@string/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/edit_action_bar" /> </linearlayout> <linearlayout android:id="@+id/thumbnail_favorites" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toleftof="@+id/thumbnail_edit" android:layout_marginright="5dip" android:padding="3dip" android:layout_centervertical="true" > <imageview android:id="@+id/favorites_image" android:contentdescription="@string/app_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/star_action_bar_unselected" /> </linearlayout> </relativelayout>
which gives me following action bar:
then set following methods in code:
actionbar ab = getactionbar(); ab.setdisplayshowcustomenabled(true); ab.setcustomview(r.id.contacts_action_bar); // id of custom_action_bar
the application crashes, when launch it. possible set custom action bar this?
i'm trying this, because can't customize enough programatically.
i know, set views, marked red, methods:
actionbar.seticon(r.id.homeicon); actionbar.settitle("some title");
and know, set action buttons, explained here.
but how add online/offline label, marked blue, in picture below?
edit: logcat output
08-24 14:16:00.257: e/androidruntime(31831): fatal exception: main 08-24 14:16:00.257: e/androidruntime(31831): java.lang.runtimeexception: unable start activity componentinfo{com.example.appcloned/com.example.appcloned.contactactivity}: android.content.res.resources$notfoundexception: resource id #0x7f0a0000 type #0x12 not valid 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activitythread.performlaunchactivity(activitythread.java:2194) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2229) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activitythread.access$600(activitythread.java:139) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activitythread$h.handlemessage(activitythread.java:1261) 08-24 14:16:00.257: e/androidruntime(31831): @ android.os.handler.dispatchmessage(handler.java:99) 08-24 14:16:00.257: e/androidruntime(31831): @ android.os.looper.loop(looper.java:154) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activitythread.main(activitythread.java:4945) 08-24 14:16:00.257: e/androidruntime(31831): @ java.lang.reflect.method.invokenative(native method) 08-24 14:16:00.257: e/androidruntime(31831): @ java.lang.reflect.method.invoke(method.java:511) 08-24 14:16:00.257: e/androidruntime(31831): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 08-24 14:16:00.257: e/androidruntime(31831): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 08-24 14:16:00.257: e/androidruntime(31831): @ dalvik.system.nativestart.main(native method) 08-24 14:16:00.257: e/androidruntime(31831): caused by: android.content.res.resources$notfoundexception: resource id #0x7f0a0000 type #0x12 not valid 08-24 14:16:00.257: e/androidruntime(31831): @ android.content.res.resources.loadxmlresourceparser(resources.java:2358) 08-24 14:16:00.257: e/androidruntime(31831): @ android.content.res.resources.getlayout(resources.java:952) 08-24 14:16:00.257: e/androidruntime(31831): @ android.view.layoutinflater.inflate(layoutinflater.java:394) 08-24 14:16:00.257: e/androidruntime(31831): @ com.android.internal.app.actionbarimpl.setcustomview(actionbarimpl.java:260) 08-24 14:16:00.257: e/androidruntime(31831): @ com.example.appcloned.contactactivity.oncreate(contactactivity.java:23) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activity.performcreate(activity.java:4531) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1071) 08-24 14:16:00.257: e/androidruntime(31831): @ android.app.activitythread.performlaunchactivity(activitythread.java:2150) 08-24 14:16:00.257: e/androidruntime(31831): ... 11 more
- yes it's possible use custom action bars. in fact majority of developers use it.
- the online/offline - assume it's
textview
being updated based on trigger of event.
edit:
post logcat!
Comments
Post a Comment