My main activity(one xml file, and one java file) contains a help button, and I want to display the whole layout(including the paragraph I typed on a Textview) after button clicked. It was successfully launched, all imageview were displayed but not the Textview.
Here's the content of the xml file:
<?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-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/tbs_background"
tools:context="limitless.the_bat_signal.aboutPage">
<TextView
tools:text="about the app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tbs_text_about"
android:textStyle="normal|italic"
android:textAlignment="center"
android:textColor="#android:color/darker_gray"
android:fontFamily="sans-serif"
android:layout_below="#+id/tbs_title_text"
android:layout_centerHorizontal="true"
tools:ignore="UnusedAttribute" />
<TextView
tools:text="#string/about"
android:id="#+id/tbs_text_aboutDetails"
android:layout_width="300dp"
android:textColor="#android:color/darker_gray"
android:textSize="16sp"
android:layout_height="wrap_content"
android:layout_below="#+id/tbs_text_about"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp" />
<ImageView
android:layout_height="wrap_content"
app:srcCompat="#drawable/tbs_title_text"
android:id="#+id/tbs_title_text"
android:adjustViewBounds="true"
android:layout_width="250dp"
android:layout_below="#+id/tbs_icon"
android:layout_centerHorizontal="true"
tools:ignore="ContentDescription" />
<ImageView
app:srcCompat="#drawable/tbs_icon"
android:layout_marginTop="14dp"
android:id="#+id/tbs_icon"
android:layout_width="128dp"
android:layout_height="128dp"
tools:ignore="ContentDescription"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/tbs_home"
android:background="#drawable/tbs_home"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/tbs_title_text"
android:layout_toEndOf="#+id/tbs_title_text"
android:layout_marginBottom="10dp" />
</RelativeLayout>.
Then my Activity 2 named aboutPage calling out the XML file above:
public class aboutPage extends AppCompatActivity {
Button btn_help;
TextView tbs_title_text;
TextView tbs_text_about_details;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
}
}.
I'm new to android, please tell me what am I missing. Thanks!
The text attribute in your code is wrong, the namespace should be android:text="#string/about" instead of tools:text=="#string/about".
So the resulting textview will look like,
<TextView
android:text="about the app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/tbs_text_about"
android:textStyle="normal|italic"
android:textAlignment="center"
android:textColor="#android:color/darker_gray"
android:fontFamily="sans-serif"
android:layout_below="#+id/tbs_title_text"
android:layout_centerHorizontal="true"
tools:ignore="UnusedAttribute" />
Fix it and you will be good to go.
The problem is you're using tools:text this is only for design view and will not translate to code. Use android:text instead.
Related
In the current version of instagram app (Todays date 24-06-2021) ,inside the profile activity/fragment when hamburgur button is pressed (or simply the 3 line icon) now a menu pops up from bottom and can be scroll down by swipe down ,previously when cliked it opens a new fragment/activity
im in love with this animation or a view and im despirat to implement it in my app
but the problem is i dont know what it is called
i want to know what it is exactly and also similar kind of animation or a view is also there in pintrest app
Screen Shot
Update 1
how can i navigate to a fragment from a bottom sheet for eg if in my bootomsheet there is 3 textview i want that if any textView is cliked it should open the respected new fragment i.e if a editprofle textView is clicked it open the editprofile fragment this is how my bottomsheet opens up
Profile_Fragment.java
accountSettings the imageView when clicked the bottomSheetopens up
accountSettings.setOnClickListener(
v -> {
BottomSheet bottomSheet = new BottomSheet();
bottomSheet.show(requireActivity().getSupportFragmentManager(), bottomSheet.get Tag());
}
);
bottom_sheet_profile.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="match_parent">
<View
android:id="#+id/slidedownview"
android:layout_width="40dp"
android:layout_height="3dp"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:background="#drawable/rounded_corner_bottomsheetline"
android:layout_marginTop="11dp"/>
<TextView
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/slidedownview"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="20dp"
android:elevation="10dp"
android:text="#string/settings"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="#+id/edit_profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/settings"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:elevation="10dp"
android:text="#string/edit_profile"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="#+id/favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edit_profile"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:elevation="10dp"
android:text="#string/favorite"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
<TextView
android:id="#+id/log_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/favorite"
android:layout_alignParentStart="true"
android:layout_marginStart="30dp"
android:layout_marginTop="17dp"
android:layout_marginBottom="15dp"
android:elevation="10dp"
android:text="#string/log_out"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="normal" />
</RelativeLayout>
Include the following library in your app.gradle file.
implementation 'com.google.android.material:material:<version>'
create custom layout bottom_sheet_dialog_layout.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
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="Settings"
android:drawableStart="#drawable/ic_settings"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive"
android:drawableStart="#drawable/ic_archive"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Activity"
android:drawableStart="#drawable/ic_activity"
android:layout_gravity="center_vertical"
android:padding="8dp"/>
....
....
....
in Class file
final BottomSheetDialog bottomSheetDialog = new BottomSheetDialog(this);
bottomSheetDialog.setContentView(R.layout.activity_sof);
TextView settings = bottomSheetDialog.findViewById(R.id.settings);
TextView archive = bottomSheetDialog.findViewById(R.id.archive);
TextView your_activity = bottomSheetDialog.findViewById(R.id.activity);
...
...
...
bottomSheetDialog.show();
If you want to click event
settings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "Copy is Clicked ", Toast.LENGTH_LONG).show();
bottomSheetDialog.dismiss();
}
});
I want to pass the contents to the text view from the edit text by using button click and also show notification that Notice posted. How to do that?? I Am new to android. Please help, if possible give a code to do the same. Please post the java code if possible. Thank You..!!
My XML code:
<?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">
<TextView
android:layout_width="250dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="RECENT NOTICES"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#ff0612"
android:textSize="30dp"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="50dp"
android:id="#+id/noticeText"
android:hint="Post Notice"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/sndnoticeBut"
android:src="#drawable/send1"
android:background="#null"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView3"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/noticeText"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/sndnoticeBut"
android:src="#drawable/send1"
android:background="#null"
<!-- Add the onClick -->
android:onClick="sendToTV"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/textView"
android:layout_toEndOf="#+id/textView" />
Do the following in the Activity containing the layout
public void sendToTV(){
String myText = null;
TextView tv = (TextView) findViewById(R.id.noticeText);
EditText et = (EditText) findViewById(R.id.textView);
myText = et.getText.toString();
tv.setText(myText);
}
On your button click your_textview.setText(your_edittext.getText().toString());
For local notification http://www.vogella.com/tutorials/AndroidNotifications/article.html
I'm trying to align 3 buttons in a row in the center of the screen. Each button will have a background color, an image, and some text under the image. I've tried using LinearLayout but I can't put the image over the button. I've tried RelativeLayout, and I managed to get them in a row, but they are not in the center of the screen. Any advices?
<Button
android:id="#+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="85dp"
android:paddingBottom="10dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:background="#drawable/light"
android:text="#string/start"
android:textColor="#color/text"
android:textSize="8pt"
android:textStyle="bold"
android:layout_marginTop="0dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_alignParentTop="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/image"
android:src="#drawable/hstart"
android:layout_alignLeft="#+id/start"
android:layout_alignStart="#+id/start"
android:layout_alignRight="#+id/start"
android:layout_alignEnd="#+id/start"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="0dp" />
Here is your Button view (your_btn_view.xml in the layout folder):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true"
android:background="#android:drawable/btn_default"
android:gravity="center" >
<ImageView
android:id="#+id/btn_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_add" />
<TextView
android:id="#+id/btn_tv"
android:text="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Here is your layout view containing three buttons:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<include
android:id="#+id/btn1"
layout="#layout/your_btn_view" />
<include
android:id="#+id/btn2"
layout="#layout/your_btn_view" />
<include
android:id="#+id/btn3"
layout="#layout/your_btn_view" />
</LinearLayout>
Then, access and fill in the appropriate TextView and ImageView in your onCreate() like so:
#Override
public void onCreate(Bundle sIS){
super.onCreate(sIS);
setContentView(R.layout.that_layout_above, this, false);
LinearLayout btn1 = (LinearLayout)findViewById(R.id.btn1);
((TextView)btn1.findViewById(R.id.btn_tv)).setText("my text");
...
Use a LinearLayout to hold a RelativeLayout for each button/image combination. "Nested" layouts is pretty common to get this type of visual effect.
I want to make a View that consists of few other standard elements. There are ProgressBar, TextViews and ImageView. I declared how to layout them in res/layout/myView.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="10dp"
tools:ignore="HardcodedText,ContentDescription" >
<ImageView
android:id="#+id/qItemImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/qItemNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#id/qItemImageView"
android:gravity="center"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ProgressBar
android:id="#+id/qProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/qItemNameTextView"
android:layout_alignParentRight="true"
android:layout_below="#+id/qItemNameTextView"
android:max="100"
android:progress="50" />
<TextView
android:id="#+id/qLevelTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/qItemImageView"
android:layout_alignTop="#id/qItemImageView"
android:text="7"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
<TextView
android:id="#+id/qTimeTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/qProgressBar"
android:layout_alignLeft="#id/qProgressBar"
android:layout_alignRight="#id/qProgressBar"
android:layout_alignTop="#id/qProgressBar"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="01:01:01"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#android:color/black" />
</RelativeLayout>
I also created a new class, but do not know how can I bind it to this resource file...
import android.content.Context;
import android.view.View;
public class QueueRowView extends View {
public QueueRowView(Context context) {
super(context);
}
}
How can I make my control look like specified in layout file?
Is there a reason why you need a separate class for this layout? You could just include this layout file into another one. If you really want the extra class, then look at Fragments.
I'm actually coding an app for Android and I need some help to do something.
I need to do a kind of popup message with this image: http://img716.imageshack.us/img716/9331/postitz.png. This image must have 2 TextView, one of them is a title and the other one is the message.
I have tried some options like Dialog with its own layout, own style, but the image fills all the screen instead of wrap the content of the TextViews. I have also tried to do it with a new Activity and occurs the same, the Image fills all the screen.
My actual layout is this:
<?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:gravity="center_vertical"
android:background="#android:color/white">
<LinearLayout
android:id="#+id/img_postit"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/postit"
android:orientation="vertical">
<TextView
android:id="#+id/note_titulo"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
<TextView
android:id="#+id/note_descr"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="30dp"/>
</LinearLayout>
</LinearLayout>
But I have tried with a lot of different combinations, RelativeLayout, FrameLayout, and I cannot find the solution to do this.
Any idea of how to resolve it?.
Thank's for all.
you said you used as a new activity. Did you use android:theme="#android:style/Theme.Dialog in your manifest file?
And be sure that the image is little bit smaller one such that it will be suitable to act as a pop up..
If you used a dialog what exactly is the problem? Didnt you get the dialog as a pop up ?
(i think the image is larger so that it might fill the entire screen)
Create your own class extending dialog.And use layout like following. I use this in one of my apps and the dialog window is wrapped around the buttons :
<?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="#drawable/background"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/ll2"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#+id/ll1"
android:gravity="left"
android:orientation="horizontal"
android:paddingBottom="5dp" >
<RadioButton
android:id="#+id/start"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/stop"
android:background="#drawable/start_on"
android:button="#android:color/transparent"
android:checked="true" />
<RadioButton
android:id="#+id/stop"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_centerInParent="true"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:background="#drawable/stop_off"
android:button="#android:color/transparent" />
<RadioButton
android:id="#+id/restart"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/stop"
android:background="#drawable/restart_on"
android:button="#android:color/transparent" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/lltext"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/detail_credit"
android:layout_below="#+id/ll2"
android:layout_marginBottom="15dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/startText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/stopText"
android:text="#string/start_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/stopText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:text="#string/stop_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="#+id/restartText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/stopText"
android:text="#string/restart_server_icon"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_below="#+id/lltext"
android:layout_centerHorizontal="true"
android:text="OK" />
</RelativeLayout>
final Dialog dialog_my = new Dialog(FIRST.this,
android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
dialog_my.setContentView(R.layout.about_us); //<PUT YOUR LAYOUT ID HERE>
TextView date = (TextView) dialog_my.findViewById(R.id.date);
TextView thought = (TextView) dialog_my.findViewById(R.id.thought);
TextView ok = (TextView) dialog_my.findViewById(R.id.ok);
TextView link = (TextView) dialog_my.findViewById(R.id.link);
TextView contact = (TextView) dialog_my.findViewById(R.id.contact);
WindowManager.LayoutParams lp = dialog_my.getWindow().getAttributes();
lp.dimAmount = 0.0f;
dialog_my.getWindow().setAttributes(lp);
dialog_my.getWindow().addFlags(
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
dialog_my.show();