我尝试实施自定义Facebook Login Button:它将完全相同,除非用户登录后它还具有额外的功能;我不想改变它的风格或任何与它的外观/感觉相关的东西。
需要在xml文件中显式调用该按钮:
<com.facebook.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
我扩展了LoginButton类并添加了一个方法(我希望我的功能发生在哪里):
public class CustomFBButton extends LoginButton{
public CustomFBButton (Context context, AttributeSet attrs) {
super(context, attrs);
}
public void enablePublishActions(final Activity activity) {
//EXTRA FUNCTIONALITY
}
}
现在,根据我的理解,我应该按照以下方式调用我的按钮(我完全按照这样做):
<com.company.helpers.FacebookClass.CustomFBButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp" />
com.company.helpers
是FacebookClass
所在的包。
CustomFBButton
是FacebookClass
中的子类。
我称之为正确吗?显然,Eclipse无法找到该类:它似乎在另一个包中寻找该类。
04-24 16:11:00.899: E/AndroidRuntime(28004): FATAL EXCEPTION: main
04-24 16:11:00.899: E/AndroidRuntime(28004): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.company.product.main/com.company.product.settings.Settings}: android.view.InflateException: Binary XML file line #30: Error inflating class com.company.helpers.FacebookClass.CustomFBButton
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.ActivityThread.access$700(ActivityThread.java:165)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1326)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.os.Looper.loop(Looper.java:137)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.ActivityThread.main(ActivityThread.java:5455)
04-24 16:11:00.899: E/AndroidRuntime(28004): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 16:11:00.899: E/AndroidRuntime(28004): at java.lang.reflect.Method.invoke(Method.java:525)
04-24 16:11:00.899: E/AndroidRuntime(28004): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
04-24 16:11:00.899: E/AndroidRuntime(28004): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
04-24 16:11:00.899: E/AndroidRuntime(28004): at dalvik.system.NativeStart.main(Native Method)
04-24 16:11:00.899: E/AndroidRuntime(28004): Caused by: android.view.InflateException: Binary XML file line #30: Error inflating class com.company.helpers.FacebookClass.CustomFBButton
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.rInflate(LayoutInflater.java:769)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
04-24 16:11:00.899: E/AndroidRuntime(28004): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
04-24 16:11:00.899: E/AndroidRuntime(28004): at com.actionbarsherlock.internal.ActionBarSherlockNative.setContentView(ActionBarSherlockNative.java:133)
04-24 16:11:00.899: E/AndroidRuntime(28004): at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
04-24 16:11:00.899: E/AndroidRuntime(28004): at com.company.product.settings.Settings.onCreate(Settings.java:34)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.Activity.performCreate(Activity.java:5372)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2267)
04-24 16:11:00.899: E/AndroidRuntime(28004): ... 11 more
04-24 16:11:00.899: E/AndroidRuntime(28004): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.company.helpers.FacebookClass.CustomFBButton" on path: /data/app/com.company.product.main-2.apk
04-24 16:11:00.899: E/AndroidRuntime(28004): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:64)
04-24 16:11:00.899: E/AndroidRuntime(28004): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-24 16:11:00.899: E/AndroidRuntime(28004): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.createView(LayoutInflater.java:565)
04-24 16:11:00.899: E/AndroidRuntime(28004): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)