I create a custom view for actionbar.When i use <inclued layout=@layout/XXXXX />
is ok.However ,when i use LayoutInflater to inflate the view ,it cannot inflate it .Here is my code
public class TitleLayout extends LinearLayout {
// private Button btn_back;
// private Button btn_edit;
public TitleLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.view_title,this);
}
}
TitleLayout is my custom view
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btn_back"
android:layout_gravity="center"
android:text="Back"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/text_title"
android:text="This is a title"
android:layout_gravity="center"
android:textSize="30sp"
android:gravity="center"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:id="@+id/btn_edit"
android:text="Edit"/>
</LinearLayout>
It is a simple view; When i use <inclued />
to inflate is ok. But use LayoutInflate will show nothing.
<!--<include-->
<!--layout="@layout/view_title"/>-->
<com.example.administrator.test.TitleLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
</com.example.administrator.test.TitleLayout>
really appreciate your help!!!