Toolbar option button is unclickable - android

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;

Related

after implementing a navigation drawer, fullscreen doesn't work properly anymore

i have added a navigation drawer to an activity and now the space where normaly the navigation bar is set (in my case it should be hidden by a fullscreen call) is occupied by a blank space. without the navigation drawer the activity works just fine, fullscreen and no blank space. i also recognized that it works fine on devices with hardwarebuttons, there is no blankspace, like on a google pixel i.e.
Layout XMLs:
Activity xml:
<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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<RelativeLayout 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"
android:orientation="horizontal">
<FrameLayout
android:id="#+id/webViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/button_panel">
<ScrollView
android:id="#+id/scrollViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="#+id/webView_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</ScrollView>
</FrameLayout>
<RelativeLayout
android:id="#+id/button_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FFF"
android:orientation="horizontal"
android:padding="5dp">
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/button_to_the_left"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:alpha="0.2"
android:background="#drawable/arrowcircle"
tools:mockup_opacity="50%" />
<Button
android:id="#+id/button_Decision1"
style="#style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="#color/colorDecision1"
android:text="#string/action_decision1"
android:textAppearance="?android:textAppearanceInverse" />
<Button
android:id="#+id/button_Decision2"
style="#style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="#color/colorDecision2"
android:text="#string/action_decision2"
android:textAppearance="?android:textAppearanceInverse" />
<Button
android:id="#+id/button_Decision3"
style="#style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="3dp"
android:layout_weight="1"
android:background="#color/colorDecision3"
android:text="#string/action_decision3"
android:textAppearance="?android:textAppearanceInverse" />
<Button
android:id="#+id/button_to_the_right"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_margin="2dp"
android:alpha="0.2"
android:background="#drawable/arrowcircle"
android:rotation="180" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<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"
app:headerLayout="#layout/nav_header_main"
app:menu="#menu/activity_main_drawer_text_act" />
following are the xml-files from the AS template fro navigation drawer
app_bar_main.xml:
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.max.mybai.controller.MbaiStartActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
content_main.xml:
<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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.example.max.mybai.controller.MbaiStartActivity"
tools:showIn="#layout/app_bar_main">
nav_header_main.xml:
<LinearLayout 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="#dimen/nav_header_height"
android:background="#color/colorPrimary"
android:gravity="bottom"
android:orientation="vertical"
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:theme="#style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:background="#mipmap/ic_launcher"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/nav_header_vertical_spacing"
android:paddingLeft="5dp"
android:text="Menu"
android:textAppearance="#style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Code from the Activity (which i took from the AS template for navigation drawer) except the fullscreen()
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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);
}
#SuppressWarnings("StatementWithEmptyBody")
#Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_camera) {
// Handle the camera action
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_slideshow) {
} else if (id == R.id.nav_save_story) {
// Save current reading progress to Shared Preferences
...
Snackbar.make(getCurrentFocus(), "Geschichte wurde gespeichert", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
public void FullScreencall() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
if (!(ViewConfiguration.get(this).hasPermanentMenuKey())) {
View decorView = getWindow().getDecorView();
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
decorView.setSystemUiVisibility(uiOptions);
}
}

Android actionbar won't show title or settings

Little confused on how to show an actionbar on my second activity. Hopefully I didn't provide too much. Basically to clarify, the actionbar works perfect on my MainActivity (title shows and settings button), but I can only see the action bar on my other activities (NO title or buttons) I also took a look in menu_main.xml and noticed the context was set to my MainActivity, so I made menu_attractions.xml and changed the context to the proper activity, but that still didn't show the title or settings button. any help would be greatly appreciated!
Nothing fancy for my MainActivity (this is where I assume the magic happens for the title/buttons??)
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<include layout="#layout/content_main" />
<include layout="#layout/app_bar"/>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
And for the MainActivity class, I search for the toolbar below... and inflate the menu
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
attractionButton = (Button) findViewById(R.id.activityButton);
}
#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;
}
Here's my actionbar
<?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:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:popupTheme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
</android.support.v7.widget.Toolbar>
Now... here's my second activity
public class AttractionsActivity extends AppCompatActivity {
private Button scheduleButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.d_activities);
Toolbar toolbar = (Toolbar) findViewById(R.id.app_bar);
setSupportActionBar(toolbar);
scheduleButton = (Button) findViewById(R.id.activies_Schedule);
scheduleButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view){
Intent scheduleIntent = new Intent(AttractionsActivity.this, ScheduleActivity.class);
startActivity(scheduleIntent);
}
});
}
#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_attractions, 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);
}
here's my layout for my second activity activity
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/img_252413"
tools:context="AttractionsActivity"
tools:showIn="#layout/d_activities">
<include layout="#layout/app_bar"
android:id="#+id/include" />
<LinearLayout
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/include">
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Schedule"
android:id="#+id/activies_Schedule" />
</FrameLayout>
<Space
android:layout_width="0dp"
android:layout_height="10dp" />
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Maps"/>
</FrameLayout>
<Space
android:layout_width="0dp"
android:layout_height="10dp" />
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Performers"/>
</FrameLayout>
<Space
android:layout_width="0dp"
android:layout_height="10dp" />
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Sponsors"/>
</FrameLayout>
<Space
android:layout_width="0dp"
android:layout_height="10dp" />
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Statics"/>
</FrameLayout>
<Space
android:layout_width="0dp"
android:layout_height="10dp" />
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Exibitors"/>
</FrameLayout>
<Space
android:layout_width="0dp"
android:layout_height="10dp" />
<FrameLayout
android:background="#ffffff"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginTop="-5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:layout_marginTop="-5dp"
android:layout_marginLeft="-10dp"
android:layout_marginRight="-10dp"
android:layout_marginBottom="-5dp"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:text="Food"/>
</FrameLayout>
</LinearLayout>
</RelativeLayout>
It seems You Have Changed the Theme for Your Second Activity.Try the following
Step 1: Add this in Your Styles.xml
<style name="AppTheme.AttractionsActivity" parent="Theme.AppCompat.Light.DarkActionBar">
Step 2: Add this in Manifest.Xml
<activity
android:name=".AttractionsActivity"
android:theme="#style/AppTheme.AttractionsActivity"
/>

gravity center not working in Custom Toolbar

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?

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);
}
}

Button inside DrawerLayout is not clickable

I've been searching for a while with this issue and i cant find solution yet.
For my design of DrawerLayout, I will not be using listview but linearlayout as container for my views. I test it first by adding a button inside the linearlayout but i cant click it.
Heres the XML.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/left_drawer"
android:background="#color/white"
android:orientation="vertical"
android:layout_gravity="start"
android:layout_width="250dp"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_test"
android:text="TEST"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<FrameLayout
android:id="#+id/container_fragment2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
</FrameLayout>
In java, I also tried to put text in the button once it is being loaded and its working.The only thing that is not working is when i click it. the drawer will just close.
/**Init Drawer*/
private void initDrawer(){
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerContainer = (LinearLayout) findViewById(R.id.left_drawer);
//mDrawerContainer.setOnClickListener(new DrawerItemClickListener());
mDrawerContainer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(context,"initDrawer",Toast.LENGTH_SHORT).show();
}
});
btn_test = (Button)mDrawerContainer.findViewById(R.id.btn_test);
btn_test.setOnClickListener(new View.OnClickListener() { //this is not working,i cant click the button
#Override
public void onClick(View v) {
Log.e("MyActivity","test");
Toast.makeText(context,"test",Toast.LENGTH_SHORT).show();
}
});
btn_test.setText("hooray"); //this one is working,it change the text to hooray once loaded
}
Im looking forward for your input guys,
Thanks a lot.
Its so ironic, I just change the positions of my layout. I transferred the linearlayout below the fragment and its now working.
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/container_fragment2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="1dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
>
</FrameLayout>
<LinearLayout
android:id="#+id/left_drawer"
android:background="#color/white"
android:orientation="vertical"
android:layout_gravity="start"
android:layout_width="250dp"
android:layout_height="match_parent">
<Button
android:id="#+id/btn_test"
android:text="TEST"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Check this ! reference
you have to set a TouchListener for your drawer layout.
eg/
gestureDetector = new GestureDetector(this, new CustomGestureListener());
mDrawerLayout.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
Remove the OnClickListener that you've set on the DrawerLayout itself.
check it----
cast your button with layout where u keep the button
here is my xml
<RelativeLayout
android:id="#+id/whatYouWantInLeftDrawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#EBF4FA">
<RelativeLayout
android:id="#+id/top_view_rel"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#color/blue_color">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:visibility="visible">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/drawer_driver_name"
android:textColor="#color/text_color"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/name_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/name"
android:layout_marginLeft="135dp"
android:text="name"
android:textAllCaps="true"
android:textColor="#color/text_color"
android:textSize="16sp"
android:visibility="gone" />
<Button
android:id="#+id/edit"
android:layout_width="30dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:background="#color/colorTransparent"
android:drawableRight="#drawable/edit1"
/>
in activity--
leftDrawerRel = (RelativeLayout)findViewById(R.id.whatYouWantInLeftDrawer);
edit= (Button)leftDrawerRel.findViewById(R.id.edit);
edit.setOnClickListener(this);

Categories

Resources