<?xml version="1.0" encoding="utf-8"?> <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- --> </RelativeLayout> <!-- , --> <RelativeLayout android:id="@+id/left_drawer" android:layout_width="300dp" android:layout_height="match_parent" android:layout_gravity="start" android:choiceMode="none" <!-- , , , --> android:clickable="true" android:background="#FFFFFF" xmlns:android="http://schemas.android.com/apk/res/android" /> </android.support.v4.widget.DrawerLayout>
public class NavigationLayout extends RelativeLayout { Button ok; public NavigationLayout(Context context,RelativeLayout parent) { super(context); initView(context,parent); } public void initView(final Context context,RelativeLayout parent) { // xml View view= LayoutInflater.from(context).inflate(R.layout.view_drawer_layout,parent,true); ok=(Button)view.findViewById(R.id.ok); ok.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context,"Ok",Toast.LENGTH_SHORT).show(); } }); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="300dp" android:background="@color/screen_background" android:layout_height="match_parent"> <Button android:layout_width="110dp" android:layout_height="55dp" android:textAllCaps="false" android:id="@+id/ok" android:text="Next" android:textStyle="bold" android:textSize="25sp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:textColor="@color/buttonTextColor" /> </RelativeLayout>
public class ParentNavigationActivity extends AppCompatActivity { NavigationLayout navigationLayout; RelativeLayout left_drawer; @Override public void setContentView(@LayoutRes int layoutResID) { super.setContentView(layoutResID); setupMenu(); } public void setupMenu() { left_drawer=(RelativeLayout) findViewById(R.id.left_drawer); navigationLayout=new NavigationLayout(getApplicationContext(),left_drawer); left_drawer.addView(navigationLayout); } }
public class MainActivity extends ParentNavigationActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_test); } }
Source: https://habr.com/ru/post/334350/
All Articles