Android actionbar won't show title or settings - android

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"
/>

Related

CardView NullPointerException onClickListener

I am trying to implement a setOnClickListener method on CardView but I keep getting a null exception whenever I switch orientation of device (works fine if I start by either portrait or landscape mode):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.navajoinc.navajoinc.navfeedbackapp/com.navajoinc.navajoinc.navfeedbackapp.feedBackCardView}:
java.lang.NullPointerException: Attempt to invoke virtual method 'void
android.widget.LinearLayout.setOnClickListener(android.view.View$OnClickListener)'
on a null object reference
My Java Class is:
public class feedBackCardView extends FragmentActivity {
CardView neutralCustomer;
CardView happyCustomer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feed_back_card_view);
neutralCustomer = findViewById(R.id.neutralCustomer);
happyCustomer = findViewById(R.id.happyCard);
neutralCustomer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(feedBackCardView.this, thank_you_positive.class);
startActivity(intent);
}
});
happyCustomer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(feedBackCardView.this, thank_you_positive.class);
startActivity(intent);
}
});
}
public void unsatisfiedCutomerSelectionMethod(View v){
singleChoiceClass unsatisfied_customer_dialog = new singleChoiceClass();
unsatisfied_customer_dialog.show(getFragmentManager(), "unsatisfied_customer_dialog");
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the main_menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.contactus:
Intent callIntent = new Intent(Intent.ACTION_DIAL);
callIntent.setData(Uri.parse("tel:800.525.5097"));
startActivity(callIntent);
break;
case R.id.visitsite:
Intent siteIntent = new Intent(Intent.ACTION_VIEW);
siteIntent.setData(Uri.parse("http://navajoinc.com"));
startActivity(siteIntent);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
}
Activity XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".feedBackCardView"
android:padding="10dp"
android:background="#color/colorWhiteSmoke"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14dp"
android:layout_gravity="center"
android:text="Please tap a response :"
android:textColor="#color/colorLightGrey" />
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:clickable="false"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/happyCard"
android:foreground="?android:selectableItemBackground"
android:clickable="true"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
app:cardElevation="3dp"
app:cardBackgroundColor="#color/cardview_light_background"
app:cardCornerRadius="3dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorWhite"
android:gravity="center">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/happy_face"
android:padding="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:textColor="#color/colorLightGrey"
android:text="Happy Customer"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/cardview_light_background"
android:layout_margin="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="11dp"
android:textColor="#color/colorTextGrey"
android:text="I have had a happy experience"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:id="#+id/neutralLayout"
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:clickable="false"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/neutralCustomer"
android:foreground="?android:selectableItemBackground"
android:clickable="true"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
app:cardElevation="3dp"
app:cardBackgroundColor="#color/cardview_light_background"
app:cardCornerRadius="3dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorWhite"
android:gravity="center">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/neutral_face"
android:padding="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:textColor="#color/colorLightGrey"
android:text="Neutral Customer"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/cardview_light_background"
android:layout_margin="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="11dp"
android:textColor="#color/colorTextGrey"
android:text="My experience was neutral"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
<LinearLayout
android:clipToPadding="false"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:foreground="?android:selectableItemBackground"
android:clickable="true"
android:onClick="unsatisfiedCutomerSelectionMethod"
android:layout_width="160dp"
android:layout_height="190dp"
android:layout_margin="10dp"
app:cardElevation="3dp"
app:cardBackgroundColor="#color/cardview_light_background"
app:cardCornerRadius="3dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/colorWhite"
android:gravity="center">
<ImageView
android:layout_width="64dp"
android:layout_height="64dp"
android:background="#drawable/angry_face"
android:padding="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:textColor="#color/colorLightGrey"
android:text="Unsatisfied Customer"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/cardview_light_background"
android:layout_margin="2dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="11dp"
android:textColor="#color/colorTextGrey"
android:text="My experience was unpleasant"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
I have tried many solutions on Stackoverflow and other websites but none of it has worked ? Could you please help with this issue?
I've tried the code and it's working. Even after rotation. However, I changed the implementation of the onclick methods to simply show a toast rather that launch an intent since you didn't provide the classes. I also ommited all the code related to the menu.
Also, why are you setting the clickable=true property on your card view if you are setting an onClickListener within your code? It's redundant. Also, I don't see any reason to assert clickable=false in your <LinearLayout> tags.
I don't think you are providing enough information to locate the error, or it's related to the classes that haven't been provided. Is the app crashing simply on rotation, or after you try clicking on something? Are you sure the crash is related to rotation, and not an attempt to launch a new activity?

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

Nothing displayed on the screen under the toolbar

I have Activiti. There is a toolbar and Fragment. But under the toolbar, this fragment is not shown. Logs all right, a fragment of work, the only problem is only with the display.
This is my code of Activity:
Toolbar toolbar;
public void initToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar1);
setSupportActionBar(toolbar);
setTitle(R.string.app_name);
toolbar.setBackgroundResource(R.drawable.header);
toolbar.setTitleTextColor(getResources().getColor(android.R.color.white));
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
initToolbar();
// Create the AccountHeader
DrawerClass.drawer(this, toolbar);
ProfileFragment profileFragment = new ProfileFragment();
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.add(R.id.profile_fragment_layout, profileFragment);
transaction.commit();
}
#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_general, 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);
}
And this layout of Activity:
<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=".GeneralActivity"
android:background="#color/event_background">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/event_background"
android:titleTextColor="#color/text_color"
android:elevation="4dp"
android:minHeight="?attr/actionBarSize"
android:paddingTop="#dimen/tool_bar_top_padding"
android:layout_marginTop="-25dp"
android:transitionName="actionBar">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/profile_fragment_layout"
android:layout_below="#+id/toolbar1">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
app:elevation="4dp"
android:src="#drawable/pencil"
app:layout_anchor="#id/toolbar1"
app:layout_anchorGravity="bottom|right|end"
app:borderWidth="0dp"/>
</android.support.design.widget.CoordinatorLayout>
If You need it's code of my Fragment:
View view;
#Bind(R.id.dad_img)
CircleImageView dad_image;
#Bind(R.id.mum_img)
CircleImageView mum_image;
public void buildDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle("Диалог");
builder.setMessage("Выберите действие");
builder.setCancelable(true);
builder.setPositiveButton("Сообщение", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); // Отпускает диалоговое окно
}
});
builder.setNegativeButton("Перевод", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss(); // Отпускает диалоговое окно
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.profile_fragment, container, false);
ButterKnife.bind(this, view);
Log.d("FRAGMENT", "working");
dad_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buildDialog();
}
});
mum_image.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
buildDialog();
}
});
return view;
}
And layout of fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/text_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:id="#+id/profile_school"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/study"
android:gravity="center"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="16sp"
android:paddingLeft="10dp"
android:text="#string/drawer_second_line"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="16sp"
android:paddingLeft="10dp"
android:layout_marginBottom="10dp"
android:text="#string/nickname" />
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="#+id/divider1"
android:layout_below="#+id/profile_school"
android:background="#android:color/darker_gray"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_below="#+id/divider1"
android:id="#+id/profile_phone"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/phone"
android:layout_marginTop="2dp"
android:gravity="center"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="5">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="16sp"
android:layout_margin="10dp"
android:layout_centerVertical="true"
android:text="#string/phone"/>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/profile_phone"
android:id="#+id/divider2"
android:background="#android:color/darker_gray"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_below="#+id/divider2"
android:id="#+id/profile_parent"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/parents"
android:gravity="center"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="5">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/dad_img"
android:layout_marginLeft="10dp"
android:src="#mipmap/ic_launcher"/>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mum_img"
android:layout_marginLeft="10dp"
android:layout_below="#+id/dad_img"
android:layout_marginTop="5dp"
android:src="#mipmap/ic_launcher"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="16sp"
android:text="#string/mum_name"
android:id="#+id/textView2"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_alignBottom="#+id/dad_img"
android:layout_toRightOf="#+id/dad_img"
android:layout_toEndOf="#+id/dad_img" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"
android:textSize="16sp"
android:text="#string/dad_name"
android:id="#+id/textView3"
android:layout_marginTop="15dp"
android:layout_marginLeft="10dp"
android:layout_alignTop="#+id/mum_img"
android:layout_toRightOf="#+id/mum_img"
android:layout_toEndOf="#+id/mum_img" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Please help me to find my mistake:)
Repeat: When I open my Activity and Fragment load, I don't see anything at view under toolbar
I fixed this problem, I added Relative layout into CoordinatorLayout:
<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=".GeneralActivity"
android:background="#color/event_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/event_background"
android:titleTextColor="#color/text_color"
android:minHeight="?attr/actionBarSize"
android:paddingTop="#dimen/tool_bar_top_padding"
android:layout_marginTop="-25dp"
android:transitionName="actionBar1">
</android.support.v7.widget.Toolbar>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/profile_fragment_layout"
android:layout_below="#+id/toolbar1">
</FrameLayout>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
app:elevation="4dp"
android:src="#drawable/pencil"
app:layout_anchor="#id/toolbar1"
app:layout_anchorGravity="bottom|right|end"
app:borderWidth="0dp"/>
</android.support.design.widget.CoordinatorLayout>

Adding images to buttons in listview

How to put images on ListView buttons? I found some tutorials but don't know how to implement in my xml that I have already. I still working only with xml files and didn't touch anything in the code of the generated MainActivity.java.
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
#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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is the current 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="vertical"
android:weightSum="1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5" >
<ImageView
android:contentDescription="#string/food"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:scaleType="centerCrop"
android:src="#drawable/food" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="match_parent"
android:layout_height="35dp"
android:padding="4dp"
android:layout_marginTop="20dp"
android:gravity="left"
android:background="#drawable/bg_button"
android:text="#string/Menu1" />
<!-- android:background="#c5e1b0" -->
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="35dp"
android:padding="4dp"
android:layout_marginTop="5dp"
android:gravity="left"
android:background="#drawable/bg_button"
android:text="#string/Menu2" />
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="35dp"
android:padding="4dp"
android:layout_marginTop="5dp"
android:gravity="left"
android:background="#drawable/bg_button"
android:text="#string/Menu3" />
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="35dp"
android:padding="4dp"
android:layout_marginTop="5dp"
android:gravity="left"
android:background="#drawable/bg_button"
android:text="#string/Menu4" />
</LinearLayout>
</LinearLayout>
So I want to add images on the left side of this 4 buttons.
Anyone can help with this task?
Update:
Currently I have this structure on the left. Half of the screen (upper) is image. Second half I have 4 buttons. I want to put image on each button on the left side like is in the right picture with where is red aquare.
Here is how you can have image and Text both on same button
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Testing" android:drawableLeft="#drawable/logo"/>

Categories

Resources