gravity center not working in Custom Toolbar - android

I created custom Toolbar.I added two images,one in center position and second left position.in xml view,everything is perfect but when i added menu elements in right side in toolbar,toolbar margined right side and image is not left position
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/md_white_1000"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/u_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff0000"/>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_below="#+id/statusBar"
android:background="?attr/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView8"
android:background="#mipmap/logo_header"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/openDrawable"
android:background="#mipmap/ic_menu_white"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<FrameLayout
android:id="#+id/statusBar"
android:layout_width="match_parent"
android:layout_height="#dimen/statusBarHeight"
android:background="#color/u_color" />
</RelativeLayout>
</LinearLayout>
<LinearLayout android:id="#+id/drawer_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start">
<LinearLayout
android:id="#+id/drawer_content"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical" >
<include layout="#layout/activity_slider_menu" />
</LinearLayout>
</LinearLayout>
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
is it a possible to add image center position when i added menu in toolbar?

Related

Toolbar option button is unclickable

I had toolbar with options in activity_one toolbar and everything worked well it was created and also clickable. All buttons were working good. But after I moved it to another activity it doesn't work. I am talking about this button
I have checked another topics with the same questions but at that topics there were mistakes in code. But I can't find any mistakes in my code. Because it was working well in another activity. Maybe I do something wrong but I can't solve this problem with that information which I have.
The code of XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.borisruzanov.social.ui.ChatActivity">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:id="#+id/toolbar"
android:background="?attr/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
<ListView
android:id="#+id/messageListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout"
android:stackFromBottom="true"
android:divider="#android:color/transparent"
android:transcriptMode="alwaysScroll"
tools:listitem="#layout/item_message"/>
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal">
<ImageButton
android:id="#+id/photoPickerButton"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#android:drawable/ic_menu_gallery" />
<EditText
android:id="#+id/messageEditText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1" />
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:enabled="false"
android:text="#string/send_button_label"/>
</LinearLayout>
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
The code of class
Toolbar toolbar;
in OnCreate
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
And two methods
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
Log.v("========>", "In oncreateMenu");
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.v("========>", "In item selected");
int id = item.getItemId();
if (id == R.id.menu_log_out){
mAuth.signOut();
}else if (id == R.id.menu_chat){
Intent intent = new Intent(this, ChatActivity.class);
startActivity(intent);
}
return true;

match_parent is not working in custom toolbar

I have made custom toolbar with search and setting icon . when i click on search icon edittext should apper with match_parent and should occupy available space till the search icon . However it is not happening . it just appear with very small space at the top-left side . Please help where i am wrong
I would like to share my whole code with xml
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DCDCDC"
android:padding="0dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="myresolver.faisal.home.com.myresolver.MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/my_toolbar"></include>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="1dp"
android:weightSum="4"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96"></ImageView>
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="3">
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
<ImageView
style="#style/icon"
android:background="#drawable/fear_96" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
mytoolbar.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 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="wrap_content"
android:background="#color/orange"
app:titleTextColor="#color/white"></android.support.v7.widget.Toolbar>
my main_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu 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">
<item
app:showAsAction="always"
android:title="#string/search"
android:icon="#drawable/ic_search_white_24dp"
android:id="#+id/search"
></item>
<item
app:showAsAction="always"
android:title="#string/setting"
android:icon="#drawable/ic_settings_white_24dp"
android:id="#+id/setting"></item>
</menu>
my search_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="#+id/searchEditText"
android:layout_width="match_parent" // THIS IS NOT WORKING
android:layout_height="wrap_content"
android:imeOptions="actionSearch"
android:inputType="text" />
</LinearLayout>
My activity
EditText searchEditText;
boolean isSearchBoxOpen = false;
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onPrepareOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return super.onPrepareOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.search:
onSearchedHandler();
break;
case R.id.setting:
Toast.makeText(this, "Setting is UnderConstruction", Toast.LENGTH_LONG).show();
break;
}
return super.onOptionsItemSelected(item);
}
public void onSearchedHandler() {
if (isSearchBoxOpen) {
String word = searchEditText.getText().toString();
if (word != null) {
Toast.makeText(this, "Searching for ..." + word, Toast.LENGTH_LONG).show();
}
} else {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.search_layout);
actionBar.setDisplayShowTitleEnabled(false);
searchEditText = (EditText) actionBar.getCustomView().findViewById(R.id.searchEditText);
searchEditText.requestFocus();
InputMethodManager keyboard = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
keyboard.showSoftInput(searchEditText, InputMethodManager.HIDE_IMPLICIT_ONLY);
isSearchBoxOpen = true;
}
}
#Override
public void onBackPressed() {
if (isSearchBoxOpen) {
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
isSearchBoxOpen = false;
return;
}
super.onBackPressed();
}
Use the below code for toolbar xlm layout :
<android.support.v7.widget.Toolbar
xmlns:app="schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/primaryColor"
android:contentInsetLeft="0dp"
android:contentInsetStart="0dp"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp"
android:contentInsetRight="0dp"
android:contentInsetEnd="0dp"
app:contentInsetRight="0dp"
app:contentInsetEnd="0dp" />
When the custom view is inflated as a result of calling setCustomView(resId), wrap_content is forced upon it (if you look into the view dump, you can see that the wrapping LinearLayout is shrunk, not the EditText).
You can set the custom view in the following way:
View customView = LayoutInflater.from(this).inflate(R.layout.search_layout, null);
ActionBar.LayoutParams params = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
actionBar.setCustomView(customView, params);
just add this line to take full width
app:contentInsetStart="0dp"
The padding in the RelativeLayout in main_activity.xml is preventing it from taking the full space so instead of having
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DCDCDC"
android:padding="0dp"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="myresolver.faisal.home.com.myresolver.MainActivity">
you move the paddings to the scrollview such that
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/toolbar"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:fillViewport="true">

CollapsingToolbarLayout with 2 pin layout

I write this code but not works properly. I want the imageview collapse in parallax mode, and toolbar and relative layout pin at top of the screen. they pin and don't scroll but the relative layout cover on the toolbar. I want relative layout stay bottom of toolbar and don't scroll.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout
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" >
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:layout_height="250dp"
android:text="New Button"
android:id="#+id/button" />
<Button
android:layout_width="wrap_content"
android:layout_height="250dp"
android:text="New Button"
android:id="#+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="250dp"
android:text="New Button"
android:id="#+id/button3" />
<Button
android:layout_width="wrap_content"
android:layout_height="250dp"
android:text="New Button"
android:id="#+id/button4" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/appBar"
android:background="#44C8F5">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/CollapsingToolbarLayout"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/header_image"
android:src="#drawable/header_test"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:layout_collapseMode="parallax"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
<android.support.v7.widget.Toolbar
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:id="#+id/toolbar"
app:layout_scrollFlags="enterAlways"
app:layout_collapseMode="pin">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/footer_appbar_padding"
app:layout_scrollFlags="enterAlways"
android:focusableInTouchMode="false">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right|center_vertical">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView2" />
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView2"
android:src="#drawable/faranesh_logo"
android:layout_gravity="right|center_vertical" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button5"
android:layout_gravity="left|center_vertical" />
</FrameLayout>
</RelativeLayout>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
public class MainActivity extends AppCompatActivity {
private CollapsingToolbarLayout collapsingToolbar;
private ImageView headerImage;
private Toolbar toolbar;
private Drawer result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_custom_container_drawer);
getSupportActionBar().setDisplayShowTitleEnabled(false);
AppBarLayout.OnOffsetChangedListener mListener = new AppBarLayout.OnOffsetChangedListener() {
#SuppressLint("NewApi")
#Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
headerImage.setImageAlpha((int)( 255*(((double)(headerImage.getHeight()+verticalOffset)/headerImage.getHeight()))));
}
};
((AppBarLayout) findViewById(R.id.appBar)).addOnOffsetChangedListener(mListener);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Unable to click the right to left DrawerLayout items

I have an activity that displays a drawer layout when a menu item is clicked thus its direction is from right to left. I manage to display the navigation menu using the following code.
public class Forecast_details extends ActionBarActivity implements OnChartValueSelectedListener {
....
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//return false;
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
if(id==R.id.Options){
if (mDrawerlayout.isDrawerOpen(Gravity.END)){
mDrawerlayout.closeDrawer(Gravity.END);
}else
mDrawerlayout.openDrawer(Gravity.END);
}
return super.onOptionsItemSelected(item);
}
My Navigation drawer contains a static list so I did not bother to make a listview out of it as seen below,
However I cannot click my items inside the Drawer Layout, or anything in the view even v4.widget.DrawerLayout in my xml is unclickable. Below is the two xml file that I used.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar"
></include>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout_right"
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true">
<include layout="#layout/nav_drawer_right" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.36" >
....
</LinearLayout>
</ScrollView>
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
nav_drawer_right.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView_right"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#2c3e50"
android:paddingTop="20dp" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/container_fragment2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginTop="1dp" >
</FrameLayout>
<LinearLayout
android:id="#+id/linearLayout_menuconatiner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:clickable="true"
android:orientation="vertical"
android:paddingLeft="2dp"
android:paddingRight="2dp" >
<ImageView
android:id="#+id/imageView_forward"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/darkblue"
android:clickable="true"
android:onClick="SendClick"
android:padding="5dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_forward" />
<View
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/separatorcolor"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
<ImageView
android:id="#+id/imageView_request"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/darkblue"
android:padding="5dp"
android:src="#drawable/ic_request" />
<View
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/separatorcolor"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
<ImageView
android:id="#+id/imageView_reloadvnet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/darkblue"
android:padding="5dp"
android:src="#drawable/ic_updatevnet" />
<View
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/separatorcolor"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
<ImageView
android:id="#+id/imageView_reloadvsms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/darkblue"
android:padding="5dp"
android:src="#drawable/ic_updatevsms" />
<View
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/separatorcolor"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
<ImageView
android:id="#+id/imageView_feedback"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/darkblue"
android:padding="5dp"
android:src="#drawable/ic_feedback" />
<View
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/separatorcolor"
android:paddingLeft="2dp"
android:paddingRight="2dp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
Please help.. I tried a lot of things to make it work like using a listview instead but I still have no luck.. please do help, Im new at using drawer layout so there may be some more things I need to know.. Thank you in advance..
To prevent return OnClickListener to parent layout require set android:clickable="true" in drawerLayout container.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout_right"
android:layout_gravity="end"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2.36" >
....
</ScrollView>
<include layout="#layout/nav_drawer_right" />
</android.support.v4.widget.DrawerLayout>
nav_drawer_right.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView_right"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#2c3e50"
android:paddingTop="20dp" >
....
</ScrollView>
in your Activity
public class MainActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DrawerLayout mDrawerLayout= (DrawerLayout) findViewById(R.id.drawer_layout_right);
ScrollView sV = (ScrollView) findViewById(R.id.scrollView1);
mDrawerLayout.openDrawer(Gravity.RIGHT);
sV.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("drawer click >>>>>>>>>>>>>>>>>>");
}
});
}
}

AppCompat overflow menu overlapping actionbar

I have been working on adding the new appcompat-v7:21.0.0 to my project. For some reason, my overflow menu on my actionbar decides to overlap my actionbar when opening. It should be opening below the actionbar.
Here is my code for base layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<FrameLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"/>
<RelativeLayout
android:id="#+id/top_status"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:layout_gravity="top|center"
android:background="#color/message_bottom_background"
android:gravity="center_horizontal"
tools:ignore="UselessParent"
android:visibility="gone">
<ImageView
android:id="#+id/top_warning_thumb"
android:src="#drawable/ic_action_warning"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:contentDescription="#string/top_warning_thumb_desc"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:visibility="gone"/>
<TextView
android:id="#+id/top_warning_text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="#string/test_text_shortest"
android:layout_toEndOf="#id/top_warning_thumb"
android:layout_toRightOf="#id/top_warning_thumb"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:textSize="20sp"
android:textColor="#color/theme_primary_background"
android:layout_marginTop="1sp"
/>
</RelativeLayout>
</FrameLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:orientation="vertical"
android:background="#color/card_background">
<TextView
android:id="#+id/left_status"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:textSize="25sp"
android:lineSpacingExtra="5sp"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/test_text_shortest"
android:paddingLeft="0sp"
android:paddingRight="0sp"
android:textColor="#color/card_background"
/>
<ListView android:id="#+id/left_drawer_child"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#color/transparent"
android:dividerHeight="1dp"
android:paddingLeft="0sp"
android:paddingRight="0sp" />
</LinearLayout>
<!--android:divider="#666"-->
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Here is my code from my main activity that pertains to menus:
public class MainActivity extends ActionBarActivity implements WifiDiagnosticFragment
.OnFragmentInteractionListener,DispatchFragment.OnFragmentInteractionListener,
TextMessageViewerFragment.OnFragmentInteractionListener,
SupervisorFragment.OnFragmentInteractionListener,
WorklistFragment.OnFragmentInteractionListener, Observer {
...
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.base_menu, menu);
if (BuildConfig.BUILD_TYPE.equals("debug")){
menu.findItem(R.id.device_admin).setVisible(true);
}
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Pass the event to ActionBarDrawerToggle, if it returns true,
// then it has handled the app icon touch event
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle your other action bar items...
switch (item.getItemId()) {
case R.id.help:
android.support.v4.app.FragmentManager fm = getSupportFragmentManager();
HelpDialog helpDialog = new HelpDialog();
helpDialog.show(fm,"Help");
return true;
case R.id.device_admin:
fm = getSupportFragmentManager();
AdminDialog adminDialog = new AdminDialog();
adminDialog.show(fm,"Device Admin");
return true;
default:
return super.onOptionsItemSelected(item);
}
//return super.onOptionsItemSelected(item);
}
}
As rciovati said, this is the desired behavior: google.com/design/spec/components/menus.html

Categories

Resources