2017-07-14 55 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请标记为正确的答案,如果它工作 –