2017-07-14 52 views
1

我有一個導航抽屜,我希望我的菜單中的一個標題操作欄可以更改,我將如何更改它?順便說一下,我在我的java文件中使用了片段。如何更改我的標題操作欄(片段)?

這裏是我的代碼:

_7_ViewClient_Feedback.java

public class _7_ViewClient_Feedback extends Fragment { 
    View myView; 

    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     myView=inflater.inflate(R.layout.activity__7__view_client_feedback, container, false); 
     return myView; 


    } 

} 

我的XML文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:tools="http://schemas.android.com/tools" 
android:background="@color/colorWhite" 
> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Title:" 
    android:textSize="20dp" 
    android:textColor="@color/colorBlack" 
    android:layout_marginLeft="20dp" 
    android:layout_marginTop="30dp"/> 

<EditText 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal" 
    android:width="325dp" 
    android:background="@color/colorLightGray" 
    android:height="35dp" 
    android:layout_marginTop="30dp" 
    android:id="@+id/feedbacktitle" 
    /> 

<Button 
    android:id="@+id/button_submitfb" 
    android:layout_width="200dp" 
    android:layout_height="wrap_content" 
    android:text="Submit" 
    android:textSize="9pt" 
    android:layout_marginTop="50dp" 
    android:layout_gravity="center" 
    android:background="@color/buttonColor" 
    android:textAllCaps="false"/> 

    </LinearLayout> 

我希望你能幫助我。謝謝!

回答

1

試試這個:

((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Your Title"); 
+0

謝謝!有效! –

+0

@PateOrtega請標記爲正確的答案,如果它工作 –