0
我在佈局中嵌入了片段。這個片段有一個非常簡單的視圖(基本上只是一個樣式化的按鈕,其編程設置的按下狀態)。片段:按下按鈕時按鈕按下狀態不會恢復
當我從承載該片段的活動中開始新活動並按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>
片段中的類,我只是做到以下幾點:
- 禁用按鈕
- 設置按下按鈕的狀態爲true(所以drawable的狀態是這樣的)如圖)
我的片段類:
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);
}
}
任何想法,爲什麼按鈕的啓用狀態被保留,但按下狀態是不是?