Android manifest xml file - android

After deleting an Android xml activity file, got problem in AndroidManifest.xml file.
What can be done to cure the issue?
In an activity created an EditText field and gave it a green background. And also gave Relative layout background a custom color, but nothing happened to the layout and the text field. So decided to delete the Relative layout(not main layout) to create a fresh one. And got the problem in Android manifest xml file.
Code:
layout seekbarlayout = (RelativeLayout) findViewById(R.id.layoutwithseekbar);
seekbarlayout.setBackgroundColor(Color.parseColor(xxxxxxxx));
text1 = (EditText) findViewById(R.id.textwithseekbar);
text1.setBackgroundColor(Color.parseColor(xxxxxxx));

Well, your RelativeLayout must had EditText in it, so when you removed RelativeLayout, the EditText should be removed with it.
Structure:
main_layout.xml
|--+ RelativeLayout (layoutwithseekbar)
|--> EditText (textwithseekbar)
try making new layout set id layoutwithseekbar on it and put EditText in it
<RelativeLayout android:id="#+id/layoutwithseekbar android:layout_width="match_parent"
android:layout_height="match_parent" >
<EditText android:id="#+id/textwithseekbar" android:layout_height="wrap_content"
android:layout_width="match_parent" />
</RelativeLayout>

Related

How do I avoid repetitive TextView code?

I want to include the below layout in a main layout file, at multiple points, but at each usage, I want to change ONLY the "android:text" attribute of the text view inside the relative layout (as seen below). How can I achieve that?
P.S. I know how to include it in the main layout. This includes the relative layout (as seen below), but the main purpose of creating another layout file is because the code (of the textview) is being repeatedly used in the main layout, and the only attribute that differs is "android:text" between these repeated text views.
<?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:id="#+id/order_id_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:fontFamily="sans-serif-light"
android:padding="20dp"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
in your another Layout file you can use this .
<include layout="#layout/main_layout"/>
And From your activity class you can set text by this.
TextView tv = (TextView) findViewById(R.id.order_id_label)
tv.setText("New Text");
This is the only way you can do this .
If all TextView element arguments are the same you could define this component in a separate file using <merge> </merge> directive and then <include layout="" />
Check here how to reuse
But if any of the TextView argument is changing, i.e. android:text attribute, the best way is to separate all other TextView attributes to custom style and reuse this custom style in different xml layout files
Check here how to use styles

Can we alter the Views present in the layout xml file for the Views present inside the include tag.

I am trying to re-use an already created layout xml file in another xml file by means of
My current XML file is as below:
<?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">
<include
android:id="#+id/insertTask"
layout="#layout/activity_edit_screen">
</include>
</RelativeLayout>
The layout file activity_edit_screen has a button named "Update", I want to change that button to "Add". That is the only change between the two xml files. How can I achevie this? I am trying to re-use one xml in another. Please provide suggestions. Thanks in advance.
Try to rename the button in code behind.
Button button=(Button)findViewByID(R.id.button1);
button.setText("Add");
Try to rename the button text in onCreate() after initializing view.
Button sample_btn=(Button)findViewById(R.id.sample_btn);
sample_btn.setText("Add")
;

How to overlay an image above all activities in android

I want to overlay an image above all activities after some operation to have a feel like phone is locked. How can I do this programmatically in android ?
You can set a FrameLayout at the end of you XML layout file with an ImageView and "match_parent" dimension for both length and height. Set it's visibility to "gone" in the XML layout file. and the problematically in your code change it's visibility to visible to show this full screen Image and hide all the other components that are laid below it.
For example in your XML file put this at the end of the XML:
<FrameLayout
android:id="#+id/lockScreenLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" >
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/your_iamge"
android:contentDescription="#drawable/your_iamge" />
</FrameLayout>
So it would be the child of your root xml element.
and then in code, do this:
lockScreenLayout = (FrameLayout) findViewById(R.id.lockScreenLayout);
lockScreenLayout.setVisibility(View.VISIBLE);
One simple solution consists in setting your image as the background of the root view of your activities.

Set the button at the very bottom of the layout - Android 2.2

I have a table layout in which i have declared a button statically in the XML file. I add rows dynamically in the program. I want the button to be set at the very end of the table layout.
I tried doing that using android:layout_gravity="bottom" but that is not helping.
Any solutions ?
This is my XML
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="horizontal|vertical"
android:scrollbarStyle="outsideInset" >
<TableLayout
android:id="#+id/table"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/back"
android:layout_gravity="bottom"
/>
</TableLayout>
</ScrollView>
I don't know exactly it will work for you but what you can do is to remove your button by using remove and then add it at run time after adding all your elements.
Example:
TableLayout tv = (TableLayout ) findViewbyId(R.id.table_layout_id);
Button button = (Button) findviewbytid(R.id.button_id);
May be you need layout param of your button so you can get it easily.
LayoutParams lp = button.getLayoutParams();
remove your button from layout.
tv.removeView(button);
ADD ALL YOUR VIEW AT RUNTIME.
Add your button again.
tv.addView(button, lp);
I havnt tried this code but I think it should work. In some of the cases you don't need layout params so you can ignore it too.
I don't believe there's a way to reorder the children of a ViewGroup without removing all children and readding them in the appropriate order. If a ListView will suffice in lieu of a TableLayout, it has a addFooterView() method which would achieve what you're after.
put button outside the table and scroll-view......
i mean below the scroll-view

Adding views in Android from Java source

I'm working on an app that requires the user to either increase or decrease the number of edit texts during application run-time (eg, in the default Android contacts app).
Someone please assist with some Java source code
Assume we have a container defined in an xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/container" android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Now we can do this:
ViewGroup container = (ViewGroup) findViewById(R.id.container);
EditText editText = new EditText(this);
container.addView(editText);
Note: The container doesn't even have to be defined via xml. We can also create the container dynamically and use setContentView. It also does not have to be the root ViewGroup of your layout.

Categories

Resources