我有这个相对布局代表一个按钮:
<RelativeLayout
android:id="@+id/fragment_login_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:background="@drawable/button_facebook"
android:clickable="true"
android:paddingBottom="8dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="8dp" >
这是button_facebook.xml:
<?xml version="1.0" encoding="utf-8"?>
<!-- question mark button drawable -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/button_facebook_up" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/button_facebook_up" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/button_facebook_down" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/button_facebook_up"/>
</selector>
将此布局附加到活动时,按钮的行为按预期工作。
当附加到DrawerLayout中的片段时 - 它根本不起作用:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_activity_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" >
<!-- The main content view -->
<FrameLayout
android:id="@+id/main_activity_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true" />
<!-- The navigation drawer -->
<ListView
android:id="@+id/main_activity_menu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/pico_dark_blue"
android:choiceMode="singleChoice"
android:dividerHeight="0dp"
android:paddingLeft="15sp"
android:paddingRight="15sp" />
</android.support.v4.widget.DrawerLayout>
加了:
public class LoginFragment extends BasicFragment implements OnClickListener, Runnable{
public static final String KEY_ACCESS_TOKEN_EXPIRED = "expired";
/**
* The root {@link View} of the fragment
*/
private View rootView;
/**
* The login button {@link View}
*/
private View loginButton;
@Override
protected int getLayoutId() {
return R.layout.fragment_login;
}
@Override
protected void findViews(View view) {
this.rootView = view;
loginButton = view.findViewById(R.id.fragment_login_facebook_login);
}
@Override
protected void setViews() {
loginButton.setOnClickListener(this);
}
@Override
protected void onFinishedLoading() {
Bundle args = getArguments();
//if this fragment was loaded after access token is expired - show the info window
if (args != null && args.getBoolean(KEY_ACCESS_TOKEN_EXPIRED, false))
showInfoWindow("Login expired\nPlease re-login to application", null, false, true);
}
@Override
public void onClick(View v) {
//show info window
showInfoWindow("Connecting to Facebook", null, true, false);
//start login process
getMainActivity().getFacebookManager().login(new FacebookConnectListener(this));
}
@Override
public void run() {
// when loading process if done - start the application
getMainActivity().startApplication();
}
@Override
public void onRequestComplete(JSONObject response) {
}
}
我该如何解决?