レイアウトにフラグメントが埋め込まれています。このフラグメントは、非常に単純なビュー(基本的に、押された状態がプログラム的に設定されたスタイル付きのボタン)を持っています。フラグメント:ボタンを押した状態がBACKを押しても復元されない
フラグメントをホストしているアクティビティから新しいアクティビティを開始し、元のアクティビティに戻るためにBACKを押すと、ボタンはまだ無効になっていますが、非押し状態が表示されます。
layout.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"
android:orientation="vertical" >
<fragment
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
class="com.mypackage.NavigationDrawerFragment"
android:gravity="bottom"
android:padding="5dp" />>
</RelativeLayout>
fragment_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:orientation="horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingBottom="10dp" >
<Button
android:id="@+id/nav_home"
style="@style/navigation_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="@drawable/button_home"
android:text="HOME"
android:textColor="@drawable/button_text" />
</RelativeLayout>
、私は単純に次の操作を行います。
- は
- を設定し、ボタンを無効にしますボタンの押された状態を真にします(したがって、ドロアブルのダウンステート
public class NavigationDrawerFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mDrawer = inflater.inflate(R.layout.fragment_navigation_drawer, container, false); mButtonHome = (Button) mDrawer.findViewById(R.id.nav_home); mButtonHome.setEnabled(false); mButtonHome.setPressed(true); } }
ボタンの有効状態が保存されている理由の任意のアイデアを、しかし、押された状態ではありません。私のフラグメントクラス)
が示されていますか?