Bouncing off this question:
I have made a custom webview called FlingView that incorporates gesture events. The strategy in the linked question above works fine for me; my activity layout xml is fine:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/coordinator_layout_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="net.brianclements.android.WebViewActivity">
<net.brianclements.android.FlingView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:keepScreenOn="true" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="#+id/nav_view_webview_left"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_webview_drawer_left" />
<android.support.design.widget.NavigationView
android:id="#+id/nav_view_webview_right"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_webview_drawer_right" />
</android.support.v4.widget.DrawerLayout>
onCreate() does this:
setContentView(R.layout.activity_web_view);
and I've used this method to successfully load it:
mWebview = (FlingView) findViewById(R.id.webview);
Now, the problem is when I try to override functions inside of it:
mWebview = new FlingView(this, null) {
#Override
public void onLeftFling() {
Log.d(TAG, ACTIVITY_TAG + "onFling left: ");
someDynamicObject.thatCantBeUsedStatically();
}
#Override
public void onRightFling() {
Log.d(TAG, ACTIVITY_TAG + "onFling right: ");
anotherDynamicObject.thatCantBeUsedStatically();
}
};
So how do I now insert mWebview back into the layout? The first casting method made it so simple. But from my research, I believe it now involves some combination of inflators, findViewById(), addView(), removeView() but I can't seem to figure it out. Any ideas here?
Views defined in your layout are instantiated in the setContentView() call, and you can't override class methods after instantiation. Swapping out the layout-defined View for your anonymous instance with the necessary overrides would work, but it's essentially discarding the instance created from the layout, and isn't really the cleanest way to this.
I would suggest another approach. Create an interface in your FlingView class that can be used to communicate those actions back to your Activity; very similar to an OnClickListener.
For example:
public class FlingView extends WebView {
public interface FlingListener {
void onLeftFling();
void onRightFling();
}
private FlingListener mListener;
public void setFlingListener(FlingListener listener) {
mListener = listener;
}
public void onLeftFling() {
if (mListener != null) {
mListener.onLeftFling();
}
}
public void onRightFling() {
if (mListener != null) {
mListener.onRightFling();
}
}
...
}
In your Activity, after finding your FlingView instance from the inflated layout, simply set an instance of the listener on it.
setContentView(R.layout.activity_web_view);
...
mWebview = (FlingView) findViewById(R.id.webview);
mWebview.setFlingListener(new FlingView.FlingListener() {
#Override
public void onLeftFling() {
Log.d(TAG, ACTIVITY_TAG + "onFling left: ");
someDynamicObject.thatCantBeUsedStatically();
}
#Override
public void onRightFling() {
Log.d(TAG, ACTIVITY_TAG + "onFling right: ");
anotherDynamicObject.thatCantBeUsedStatically();
}
}
);
If you want to replace the current FlingView with the one you just created you need to do the following:
CoordinatorLayout cl = (CoordinatorLayout) findViewById(R.id.coordinator_layout_webview);
cl.removeViewAt(0); // removing previous flingview
cl.addView(mWebView, 0); // adding the new inflated one
Related
ViewPager2 does not support direct child views
I'm trying to transition between fragments using the following code but I get the above error when using viewpager2.
Call in fragment 1 to transition to fragment 2:
getFragmentManager().beginTransaction().replace(R.id.viewPager2, new q2_fragment()).addToBackStack(null).commit();
Viewpager2 XML in Main Layout:
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/viewPager2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="10"
android:orientation="horizontal"
android:scaleType="fitXY" />
Instantiation in Main:
final ViewPager2 viewPager2 = findViewById(R.id.viewPager2);
viewPager2.setAdapter(new QuestionsActivity.ScreenSlidePagerAdapter(this));
viewPager2.setUserInputEnabled(false);
How do I avoid this error with viewpager2?
I got the same error when I put the TabLayout before ViewPager 's closing tag
That is:
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</androidx.viewpager2.widget.ViewPager2>
Which is not Allowed!
Just Removing the ending tag and separating TabLayout will work
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Would be happy to help, please elaborate on your requirement. What exactly you want to do.
If you want to go to fragment 2 from fragment 1, at a particular point then you should use interface between fragment and activity, to tell the activity to move the viewpager to the item which has fragment 2.
Interface Pattern for Fragment to Activity
Interface
public interface FragmentCallback{
public void goTo(int pos);
}
Activity
public class MyActivity extends AppCompatActivity implements MyStringListener{
#Override
public void goTo(int pos){
yourviewpagerAdapter.setCurrentItem(pos);
}
}
public class Fragment1 {
private FragmentCallback callBack;
#Override
public void onAttach(Context context) {
super.onAttach(context);
try {
callBack = (FragmentCallback) context;
} catch (ClassCastException castException) {
/** The activity does not implement the listener. */
}
}
public void someEvent() {
if(callBack!=null) {
callBack.goTo(1);
}
}
}
As the statement says
ViewPager2 does not support direct child views
So never try to add the fragment to viewPager2 directly
i.e the following lines of code will not work with viewPager2.
getFragmentManager().beginTransaction().replace(R.id.viewPager2, new q2_fragment()).addToBackStack(null).commit();
The exception is produced if you try to add fragment directly to viewPager2 with the help of fragmentManager.
So simply remove the above lines of code to get rid of this exception.
Lets Say From Fragment_1 to Fragment_2:
In side the button click in Fragment_1
Bundle result = new Bundle(); result.putString("bundleKey", "result"); getParentFragmentManager().setFragmentResult("requestKey", result);
In side the Fragment_2 onCreate(Bundle savedInstanceState) method
getParentFragmentManager().setFragmentResultListener("requestKey", this, new FragmentResultListener() {
#Override public void onFragmentResult(#NonNull String requestKey, #NonNull Bundle bundle)
{
supported String result = bundle.getString("bundleKey"); System.out.println("----------------------------"+result);
}
});
https://developer.android.com/guide/fragments/communicate#pass-between-fragments
Use mPager.setNestedScrollingEnabled(true);
activity_main.xml content
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<WebView
android:id="#+id/ny_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ny_sms"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorBlack"
android:isScrollContainer="false"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:visibility="gone"></LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java content
package com......;
import android.Manifest;
import android.blablabla.and.other.imports;
...
...
public class MainActivity extends AppCompatActivity {
static WebView mWebView;
static LinearLayout ny_sms;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.activity_main);
ny_sms =(LinearLayout)findViewById(R.id.ny_sms);
mWebView = (WebView)findViewById(R.id.ny_web_view);
mWebView.setWebViewClient(new WebViewClient());
mWebView.loadUrl("file:///android_asset/main.html");
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new WebAppInterface(this),"Android");
}
public static void showLayoutMA() {
mWebView.setVisibility(WebView.INVISIBLE);
ny_sms.setVisibility(LinearLayout.VISIBLE);
}
}
class WebAppInterface {
Context mContext;
WebAppInterface(Context c) {
mContext = c;
}
#JavascriptInterface
public void showLayout() {
MainActivity.showLayoutMA();
}
}
main.html content
<html>
<body>
<center>
Visiblity Test
</center>
</body>
</html>
all permissions ok. al settings ok, app version 28 (android 9 pie)
im click "Visiblity Test" link not change any screen activity,
and after scroll to bottom nofication top bar click toggle auto rotate screen button
auto refresh and show LinearLayout front of the webview control.
how to fix this problem.
not showing LinearLayout and webView not invisible with "Visiblity Test" clicked. after need a refreshing action.
Sorry my English is bad :(
im found this problem,
returned error "Only the original thread that created a view hierarchy can touch its views"
So then you need me: runOnUiThread()
extend this code...
public static void showLayoutMA() {
CurrentActivitiy.runOnUiThread(new Runnable() {
#Override
public void run() {
//mWebView.setVisibility(WebView.INVISIBLE);
ny_sms.setVisibility(LinearLayout.VISIBLE);
}
});
why not use direct runOnUiThread(new Runnable() {} function, because my function is static, im add "CurrentActivitiy" declaration of MainActivity.
static Activity CurrentActivitiy;
CurrentActivitiy = (Activity)MainActivity.this;
and after few hours happy ending, problem is resolved..
I have implemented a ViewPager which connects multiple Fragments together to give off that 'scrolling view' experience as you might already know. Anyhow I have a button on my first fragment that needs to scroll the user to the second fragment. How do I get this done folks? Here's my code:
ViewPager XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</android.support.v4.view.ViewPager>
</LinearLayout>
Fragment 1:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3498db" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:layout_marginLeft="15dp"
android:layout_marginTop="25dp"
android:text="Step 1"
android:textColor="#ffffff"
android:textSize="50dp" />
<Button
android:id="#+id/step1Btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginBottom="5sp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
android:text="Next Step"
android:textColor="#FFFFFF"
android:textSize="30sp" />
</LinearLayout>
</RelativeLayout>
In order to make this post short, let's say the second fragment has the same XML.
So we have TWO fragments. Here's the fragment java class:
public class RegisterPageOne extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View v = inflater.inflate(R.layout.registration_page1, container, false);
Button nextStep = (Button) v.findViewById(R.id.step1Btn);
nextStep.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
//Where I want to call the SECOND FRAG
}
});
return v;
}
public static RegisterPageOne newInstance(String text) {
RegisterPageOne f = new RegisterPageOne();
Bundle b = new Bundle();
b.putString("msg", text);
f.setArguments(b);
return f;
}
}
help me out please :)
You can use the setCurrentItem(int item,boolean smoothScroll) method of your viewPager object to achieve this. Here is the documentation.
Saw your followup question about how to refer to the ViewPager, from your Fragment. It's pretty convoluted, for a relative newbie like me, but, I think I can get all of it... I'll give you what I did in my code. Set up a listener in the ViewPager:
public class PageViewActivity extends FragmentActivity
implements PageDisplayPortFrag.OnLinkExpectedListener {
...
}
This gets referenced in your Fragment:
private OnLinkExpectedListener mListenerLink;
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListenerLink = (OnLinkExpectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnLinkExpectedListener");
}
}
#Override
public void onDetach() {
mListenerLink = null;
super.onDetach();
}
// THIS IS THE METHOD CALLED BY THE BUTTON CLICK !!!
public void linkExpected(String ticker) {
if (mListenerLink != null) {
mListenerLink.onLinkActivity(ticker);
}
}
public interface OnLinkExpectedListener {
public void onLinkActivity(String ticker);
}
And, then, a method gets called in the ViewPager:
#Override
public void onLinkActivity(String ticker) {
// receive ticker from port click; user wants to view page in webview, for this security
//Toast.makeText(this, "Ticker item clicked: " + ticker, Toast.LENGTH_SHORT).show();
// NEHARA, YOU MAY OR MAY NOT NEED TO DO STUFF HERE
// THIS IS WHAT I NEEDED TO DO; LEAVING IT FOR THE
// getFragmentTag() EXAMPLE -- WHICH CAME FROM Stack Overflow POSTERS
// get all-important fragment tag
String frag_Tag = getFragmentTag(pager.getId(),1);
// use tag to get the webview fragment
PageXYZWebviewFrag xyzWeb = (PageXYZWebviewFrag)
getSupportFragmentManager().findFragmentByTag(frag_Tag);
// send request to the webview fragment
xyzWeb.loadPageForSelectedSecurity(ticker);
// SET THE DESIRED FRAGMENT, assumes I know the fragment number
// from when I set up the ViewPager
// switch to the webview fragment
pager.setCurrentItem(1);
}
// fragment tag getter -- very important, yet has been elusive
private String getFragmentTag(int viewPagerId, int fragmentPosition) {
return "android:switcher:" + viewPagerId + ":" + fragmentPosition;
}
I have the following in my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:id="#+id/topNav"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/stop_surfing"/>
<TextView
style="#style/Counter"
/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</LinearLayout>
When I run the method surf(), I was assuming that my linear layout would show, but instead nothing happens. Do I need to do something else to refresh the activity or something?
Here is the main activity:
public class MainActivity extends Activity{
public void onCreate(Bundle savedInstanceState){
// Snipped code //
WebView webView = (WebView)findViewById(R.id.webview);
webView.addJavascriptInterface(new JavaScriptBinder(this), "$js");
// Snipped code //
}
}
And here is the secondary class:
public class JavaScriptBinder{
Activity context;
JavaScriptBinder(Activity context){
this.context = context;
}
public void surf(String memberId){
// Snipped code //
LinearLayout top = (LinearLayout)context.findViewById(R.id.topNav);
top.setVisibility(View.VISIBLE);
}
}
surf() is called from a javascript file loaded in the webview:
function startSurfing(){
var users = document.getElementsByClassName("user");
for(var i = 0; i < users.length; i++){
users[i].addEventListener("click", function(e){
e.stopPropagation();
with(document.getElementById("black-overlay").style){
display = "block";
backgroundColor = "rgba(0,0,0,0.7)";
}
var userId = this.dataset.id;
$js.surf(userId);
}, false);
}
}
The documentation states that the code is run in a different Thread, so of course, you can't update your UI from this method just like this, see here:
http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String)
JavaScript interacts with Java object on a private, background thread of this WebView. Care is therefore required to maintain thread safety.
So what you need to do, is to run that code in the UI Thread.
Also, you need to annotate your method with #JavascriptInterface, for the method to be callable for Android 4.2 and above.
Try with this:
#JavascriptInterface
public void surf(String memberId){
// Snipped code //
final LinearLayout top = (LinearLayout)context.findViewById(R.id.topNav);
context.runOnUiThread(new Runnable(){
#Override
public void run(){
top.setVisibility(View.VISIBLE);
}
});
}
Since the google has introduced the navigation drawer, I tried to use this component to create a facebook-like menu. The problem is , the visual effect is seems to be different.
The google one has the action bar retain when the drawer is open while the facebook one does not.Instead, the whole screen has pushed to right side
I have found there are some lib can achieve this, but since I prefer not include third party lib in the project, are there any way to achieve this ? Thanks
Code based on navigation drawer tutorial
protected void setupMenu(List<String> list, final ListView menu) {
Adapter customAdapter = new Adapter(getActionBar().getThemedContext(),
R.layout.item, list);
menu.setAdapter(customAdapter);
menu.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
final int pos, long id) {
String selected = ((TextView) view.findViewById(R.id.itemTxt))
.getText().toString();
// define pass data
final Bundle bData = new Bundle();
bData.putString("itemSelect", selected);
drawer.setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
#Override
public void onDrawerClosed(View drawerView) {
super.onDrawerClosed(drawerView);
FragmentTransaction tx = getSupportFragmentManager()
.beginTransaction();
tx.replace(R.id.mainContent, Fragment.instantiate(
MainActivity.this,
"com.example.utilities.ContentPage", bData));
tx.commit();
}
});
drawer.closeDrawer(menu);
}
});
}
Well creating a custom navigation drawer is the best solution for you.
I understand you do not want to use third party but this can be a quick solution to your problem Sliding Menu Lib link.
Hope this Helps.
<android.support.design.widget.NavigationView
android:id="#+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
>
<include
layout="#layout/nav_header_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.design.widget.NavigationView>
Remove the last two lines
in the default code
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer"
Here is a quick solution that worked for me :
<include
android:id="#+id/left_drawer"
android:orientation="vertical"
**android:layout_width="320dp"**
android:layout_height="match_parent"
android:layout_gravity="start"
layout="#layout/drawer"/>
Set width of included layout . For devices with different screen size you can dynamically set the width of this included layout .
All the best !!!!
If you will check source code of DrawerLayout, you will see, that resposnible for this minimum margin is the variable mMinDrawerMargin
So, there are atleast 2 solutions(tricks)
1. extend DrawerLayout and set this variable to 0 with reflection.
call this method from all constructors.
private void init() {
try {
Field declaredField = getClass().getSuperclass().getDeclaredField("mMinDrawerMargin");
declaredField.setAccessible(true);
declaredField.setInt(declaredField, 0);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
not so tricky
overryde onMeasure method like this
#Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// taken from parents logic
float density = this.getResources().getDisplayMetrics().density;
int minMargin = (int) (64.0F * density + 0.5F);
int widthMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
int newWidth = MeasureSpec.makeMeasureSpec(widthSize + minMargin, widthMode);
super.onMeasure(newWidth, heightMeasureSpec);
}
I also created sample project here https://bitbucket.org/wnc_21/fsnavigationdrawer
this problem is caused by margin so we have to reset the width :
i solved this problem by implementing DrawerListener and wrapping ListView inside a LinearLayout for making rooms for other views beside list view
here is my listener
public class NavigationDrawer implements DrawerLayout.DrawerListener {
private DrawerLayout mDrawerLayout;
protected boolean expanded = false;
NavigationDrawer(Activity activity) {
this.activity = activity;
}
public NavigationDrawer bindDrawerLayout(int id) {
mDrawerLayout = (DrawerLayout) activity.findViewById(id);
mDrawerLayout.setDrawerListener(this);
return this;
}
#Override
public void onDrawerSlide(View drawerView, float slideOffset) {
if (!expanded) {
Log.i("margin", "here we are");
LinearLayout layout = (LinearLayout) findViewById(R.id.left_drawer);
layout.getLayoutParams().width = getResources().getDisplayMetrics().widthPixels;
layout.requestLayout();
expanded = true;
}
}
#Override
public void onDrawerOpened(View drawerView) {
}
#Override
public void onDrawerClosed(View drawerView) {
}
#Override
public void onDrawerStateChanged(int newState) {
}
}
here is my layout :
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/application_drawer_layout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<FrameLayout
android:id="#+id/application_content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="start"
android:background="#000000"
android:orientation="vertical">
<ListView
android:id="#+id/application_left_drawer"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#111"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
If you want to implement like facebook sliding menu, then you to use androids SlidingPaneLayout instead of NavigationDrawer.
<android.support.v4.widget.SlidingPaneLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:layout_width="250dp"
android:layout_height="match_parent"
android:background="#CC00FF00" />
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="match_parent"
android:background="#CC0000FF" >
// add toolbar and other required layouts
</LinearLayout>
</android.support.v4.widget.SlidingPaneLayout>
add toolbar instead of actionbar and apply no actionbar theme.