relativelayout makes my button stop working - android

when i use linearlayout everything works like its supposed except my button is at the top and not the bottom of the screen.
when i use relativelayout my button is on the bottom like its supposed to but only works for the first listview entry after that it stops working...
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button android:id="#+id/plus"
android:background="#drawable/selector"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
<TextView android:id="#android:id/empty" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="#string/helptxt1"
/>
</RelativeLayout>
..
public void addListenerOnButton() {
final Context context = this;
button1 = (Button) findViewById(R.id.plus);
button1.setOnClickListener(new OnClickListener() {
// #Override
public void onClick(View arg0) {
createNote();
// Intent intent = new Intent(context, QuoteEdit.class);
// startActivity(intent);
}
});
}
private void createNote() {
Intent i = new Intent(this, QuoteEdit.class);
startActivityForResult(i, ACTIVITY_CREATE);
}

Your buttons wont work because when you use a Relative layout all the views/buttons are placed in the same location unless you place them above or below each other. Try doing this with your layout:
<Button
android:id="#+id/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/plus" >
</ListView>
or you can add an onClick to your button:
<Button
android:id="#+id/plus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="myClickMethod" />
and in your code
public void myClickMethod(View view) {
createNote();
}

Related

SlidingDrawer underlap in RelativeLayout

I used a SlidingDrawer like in this tutorial
It works in a LinearLayout, but there is always a whitespace depending of the hight of the slider and all other stuff show up below the whitespace.
The soloution should be to use a Relative Layout. This deletes the whitespace but the handlerbutton from the slider seems to be under the content in the scrollview and don't do anything by clicking on it. See the screenshot
MainActivity.xml
<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="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="#+id/tbar"
layout="#layout/primerdivisor" />
<SlidingDrawer
android:id="#+id/SlidingDrawer"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:content="#+id/contentLayout"
android:handle="#+id/slideButton"
android:orientation="vertical"
android:padding="10dip"
android:rotation="180">
<!-- Handle button -->
<Button
android:id="#+id/slideButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/button_selector"
android:ems="10"
android:rotation="180"
android:text="Show" android:clickable="true"/>
<!-- Content Layout -->
<LinearLayout
android:id="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFCC"
android:gravity="center"
android:orientation="vertical"
android:padding="10dip">
<Button
android:id="#+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#drawable/button_selector"
android:text="Button 1"
android:textColor="#color/textBlack" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#drawable/button_selector"
android:gravity="center"
android:padding="5dp"
android:text="Text View Item"
android:textColor="#color/textBlack" />
</LinearLayout>
</SlidingDrawer>
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical">
....
MainActivity.java
...
private void createSlider(){
slideButton = (Button) findViewById(R.id.slideButton);
slidingDrawer = (SlidingDrawer) findViewById(R.id.SlidingDrawer);
b1 = (Button) findViewById(R.id.Button01);
textView = (TextView) findViewById(R.id.text);
// Setting Listeners to all buttons and textview
setListeners();
// Listeners for sliding drawer
slidingDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener() {
#Override
public void onDrawerOpened() {
// Change button text when slider is open
Log.i("----","blaaaaaa open");
slideButton.setText("Close");
}
});
slidingDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener() {
#Override
public void onDrawerClosed() {
// Change button text when slider is close
slideButton.setText("Open");
}
});
}
// Listeners method
void setListeners() {
b1.setOnClickListener(this);
textView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// Toast shown on sliding drawer items click
if (v.getId() == R.id.text) {
Toast.makeText(MainActivity.this, textView.getText() + " Clicked",
Toast.LENGTH_SHORT).show();
} else {
Button b = (Button) v;
Toast.makeText(MainActivity.this, b.getText() + " Clicked",
Toast.LENGTH_SHORT).show();
}
}
...
The slider should overlap the scrollview when its whiped out
In view hierarchy terms, views defined at the beginning of your layout XML are "deeper" than those defined later.
In your case your ScrollView is added to the hierarchy after your SlidingDrawer so what your seeing is to be expected.
Move your SlidingDrawer to below your ScrollView and it should be above it.

Button click event not fire properly in <include> tag in ANDROID

I have three XML files are
1) Header
2) FirstActivity
3) SecondActivity.
header.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Button 1"
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="first1"
>
</Button>
<Button
android:text="Button 2"
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="second"
>
</Button>
</LinearLayout>
firstactivity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<include layout="#layout/headerfile"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="100dip"
>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Phone Detail"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/simid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/imeino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/phoneno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</RelativeLayout>
HeaderActivity.java
public class HeaderActivity extends Activity {
Button b1,b2;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.headerfile);
b1 = (Button)findViewById(R.id.button1) ;
b2 = (Button)findViewById(R.id.button2) ;
} //onCreate over
public void first1(View v)
{
Intent i =new Intent(this,firstactivity.class);
startActivity(i);
finish();
}
public void second(View v)
{
Intent i1 =new Intent(this, secondactivity.class);
startActivity(i1);
finish();
}
}
But I got ERROR every time …
Log-cat :
ERROR/AndroidRuntime(328): java.lang.IllegalStateException: Could not find a method first1
(View) in the activity class com.contactDetails.ContactDetailsActivity for onClick handler on view class
android.widget.Button with id 'button1'
In ContactDetailsActivity.java class you should add below method
public void first1(View v)
{
// onlick code
}
<include> tags include all the elements in your root layout. So you can always access them using findViewById on your Activity.
You could use another way to handle onClickListener of your Button..
You don't have to write separate Activity for handling include layout views....
you can directly access that buttons from activity where you have used view (i.e. firstactivity.xml).
Try This..
Button b1 = (Button) findViewById(R.id.button1);
Button b2 = (Button) findViewById(R.id.button2);
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i =new Intent(this,firstactivity.class);
startActivity(i);
finish();
}
});
b2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i1 =new Intent(this,secondactivity.class);
startActivity(i1);
finish();
}
});
and Remove onClick property from both Button

How to create a Button in the camera view in vuforia?

I am using Vuforia AR sdk and want to create a button on the camera preview on the screen.
I cannot figure out where and how to add the button.
I have edit the camera_overlay_udt.xml like this.. In my layout design i have placed back button and listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:src="#drawable/back" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Swipart"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/arcstarButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:src="#drawable/star_button" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/favListingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ListView
android:id="#+id/favlist"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="7dp"
android:cacheColorHint="#00000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#color/overlay_bottom_bar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1" >
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/overlay_bottom_bar_separators" />
<ImageButton
android:id="#+id/camera_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:contentDescription="#string/content_desc_camera_button"
android:onClick="onCameraClick"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/camera_button_background" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/bottom_bar"
android:background="#color/overlay_bottom_bar_separators" />
</RelativeLayout>
after that please Edit that ImageTargets.java class
private void addOverlayView(boolean initLayout) {
// Inflates the Overlay Layout to be displayed above the Camera View
LayoutInflater inflater = LayoutInflater.from(this);
mUILayouts = (RelativeLayout) inflater.inflate(
R.layout.camera_overlay_udt, null, false);
mUILayouts.setVisibility(View.VISIBLE);
// If this is the first time that the application runs then the
// uiLayout background is set to BLACK color, will be set to
// transparent once the SDK is initialized and camera ready to draw
if (initLayout) {
mUILayouts.setBackgroundColor(Color.TRANSPARENT);
}
// Adds the inflated layout to the view
addContentView(mUILayouts, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Gets a reference to the bottom navigation bar
mBottomBar = mUILayouts.findViewById(R.id.bottom_bar);
// Gets a reference to the Camera button
mCameraButton = mUILayouts.findViewById(R.id.camera_button);
mCameraButton.setVisibility(View.GONE);
favButton = (ImageButton) mUILayouts.findViewById(R.id.arcstarButton);
listview = (ListView) mUILayouts.findViewById(R.id.favlist);
backButton = (ImageButton) mUILayouts.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
finish();
}
});
listview.setVisibility(View.GONE);
galleryList = SendFile.getFavourites();
if (galleryList != null) {
gridviewAdapter = new GridviewAdapter(ImageTargets.this);
listview.setAdapter(gridviewAdapter);
}
favButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (galleryList != null && galleryList.size() > 0) {
if (listview.getVisibility() == View.GONE) {
listview.setVisibility(View.VISIBLE);
} else {
listview.setVisibility(View.GONE);
}
} else {
Toast.makeText(ImageTargets.this, "Favourites not fond",
Toast.LENGTH_LONG).show();
}
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paramAdapterView,
View paramView, int positon, long paramLong) {
SendFile.setFavourite(galleryList.get(positon));
Intent intent = new Intent(ImageTargets.this,
LoadingScreen.class);
Bundle bundle = new Bundle();
bundle.putInt("x", x_Axis);
bundle.putInt("y", y_Axis);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
showDialogHandler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Server Response: " + aResponse, Toast.LENGTH_SHORT)
.show();
showAlertDialog(aResponse);
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Not Got Response From Server.", Toast.LENGTH_SHORT)
.show();
}
};
};
loadingDialogHandler.captureButtonContainer = mUILayouts
.findViewById(R.id.camera_button);
mUILayouts.bringToFront();
}
They showing there layouts using handlers
Start you camera preview in a normal way. Place a layout on top of it with transparent background like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ff000000"
android:layout_height="match_parent">
<ImageView
android:id="#+id/start_image_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:src="#drawable/scan_image"/>
</RelativeLayout>
In java file, you can add this layout like this:
private View mStartupView;
mStartupView = getLayoutInflater().inflate(
R.layout.startup_screen, null);
// Add it to the content view:
addContentView(mStartupView, new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
This way you will get to see your button on top of camera preview. Hope it helps
You can add buttons in cameraoverlay layout which is in layout folder and you can initialize buttons in initAR function which is in mainactivity.
Step 1: Add the button in the camera_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
style="#android:style/Widget.ProgressBar"
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="51dp"
android:text="Button" />
</RelativeLayout>
Step 2: Edit the ImageTargets.java class
private static final String LOGTAG = "ImageTargets";
private Button b1;
Step 3: Modify the initApplicationAR() function of ImageTargets.java class
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
b1.setVisibility(View.GONE);
}
});
}
Now lay back and watch your button disappear on a click!
Although it's a long time since the post.. yet I found one article.. wherein you can have the desired thing..
Ref: https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82
Solution:
Step1: Make a custom layout XML file (vuforia_widget_screen.xml). For example, button has been added.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:text="#string/welcome" />
</FrameLayout>
Step 2: Make following changes in the UnityPlayerActivity.java
Replace "setContentView(mUnityPlayer);" with
setContentView(R.layout.vuforia_widget_screen);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
-> For anyone, who will face the issue in future. :)

Android RelativeLayout and OnClickListener

I found many many threads and answers on how to make a Relative layout respond to click event. I've implemented my layout according to them. But still OnClickListener is not called. I have also given selector for it and it works well.
my_list_item xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/air.com.jingit.mobile"
android:layout_width="match_parent" android:layout_height="#dimen/actionBarHeight"
android:clickable="true"
android:background="#drawable/my_list_selector">
<com.loopj.android.image.SmartImageView
android:layout_width="#dimen/actionBarHeight"
android:layout_height="#dimen/actionBarHeight"
android:id="#+id/image"
android:scaleType="fitCenter"
android:layout_marginLeft="20dp"
android:clickable="false"
android:focusable="false"/>
<com.uma.mobile.view.CustomTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Loading..."
android:id="#+id/userName"
app:typeface="fonts/HelveticaNeue"
app:customStyle="Regular"
android:textSize="20sp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/image"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:textColor="#000"
android:clickable="false"
android:focusable="false"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#aaa"
android:layout_alignBottom="#+id/image"></FrameLayout>
and this is where I inflate the view:
public MyListItem(final Context context, final Integer retailerId) {
super(context);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.my_list_item, this);
image = (SmartImageView) view.findViewById(R.id.image);
userName = (CustomTextView) view.findViewById(R.id.userName);
setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Log.i("INSIDE LIST","CLICK");
}
});
}
Edit 1:
This Relative layout is added to a linear layout which is inside a scrollview, so that it works like a list view. Does this has something to do???
list_view.xml
<?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="wrap_content"
android:background="#eee">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/scrollView" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/listContainer" />
</ScrollView>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_centerHorizontal="true"
android:src="#drawable/up_indicator"
android:layout_alignBottom="#+id/scrollView" />
Once i had a RelativeLayout not firing onClick event and it was because i had a Button in the middle of it, and the Button's onClick event was being fired, instead of the RelativeLayout one. Solved it implementing a listener for both of them:
OnClickListener listener = new OnClickListener() {
public void onClick(View v) {
//Handle onClick
}
};
relativeLayout.setOnClickListener(listener);
button.setOnClickListener(listener);
Hope it helps!
Add OnClickListener in your RelativeLayout java Class

How to setting listener for button inside the Crouton Toast and clear that Crouton Toast using that button?

I have an app, which shows toast below the actionbar. I'm using Crouton library for displaying toast. Here I'm placing custom layout for toast, that layout contains one textview and one button (for close option). So Toast appears with button. If I click that it should close the toast but nothing happens.. Below Code for this example. Any Help Appreciated
MainActivity.java
public class MainActivity extends SherlockActivity implements OnClickListener {
private View customToastView;
private TextView customToastMessageView;
private Button customToastCloseButton;
private Button doneButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doneButton = (Button) findViewById(R.id.done_button);
customToastView = getLayoutInflater().inflate(R.layout.toast_custom_layout, null);
customToastMessageView = (TextView) customToastView.findViewById(R.id.messages);
customToastCloseButton = (Button) customToastView.findViewById(R.id.close_button);
customToastCloseButton.setOnClickListener(this);
doneButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Crouton.cancelAllCroutons();
customToastMessageView.setText("Message");
Crouton.show(this, customToastView);
break;
case R.id.close_button:
Crouton.cancelAllCroutons();
break;
}
}
}
toast_custom_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="23dp"
android:text="Button" />
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/done_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:text="Button" />
</RelativeLayout>

Categories

Resources