I am trying to create a table view with a text view and a button in android. Below is my sample code ( work in progress ). As I am very new to android please help me how to arrange the text view and the button as in the image. Now I am getting button and text view. But its weird.
My Code
TableLayout table = (TableLayout)findViewById(R.id.tableLayout_1);
for (int i = 0; i<30; i++)
{
TableRow row = new TableRow(this);
row.setBackgroundColor(Color.DKGRAY);
TextView tv = new TextView(this);
Button btn=new Button(this);
tv.setTextAppearance(getApplicationContext(), R.style.maxWid);
tv.setText("Sample Text Here");
row.addView(tv);
btn.setText("Approves");
row.addView(btn);
table.addView(row);
}
Style.xml
<style name="maxWid">
<item name="android:textStyle">bold|italic</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:layout_width">fill_parent</item>
</style>
main_layout.xml
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
android:layout_weight="1">
<TableLayout
android:id="#+id/tableLayout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
</TableLayout>
</ScrollView>
Expected format
Fighting with this since 1 day.. Please help
Thanks in advance!
what you can do here is create a layout xml using RelativeLayout and then add that into your TableRow.
Related
I looked everywhere, but for the moment works.
here is my code:
<Spinner
android:id="#+id/departement"
android:layout_width="match_parent"
android:layout_height="25dp"
android:background="#color/colorAccent"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_vertical|center_horizontal"
/>
Spinner departement = (Spinner)sender;
((TextView)departement.GetChildAt(0)).SetForegroundGravity(GravityFlags.CenterHorizontal);
((TextView)departement.GetChildAt(0)).SetTextColor(Color.White);
the color works, but the center position does not. do you have an idea ?
You can use a new xml to define the content of that item in Spinner.
And cusotmize the style in that xml .
Item.xml
<?xml version="1.0" encoding="utf-8" ?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center" //center
android:textColor="#android:color/holo_red_dark"/> //Textcolor
Set in Adapter
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,Resource.Layout.Item,items);
departement.Adapter = adapter;
I saw this link: https://learn.microsoft.com/en-us/xamarin/android/user-interface/controls/spinner
I want to change color of the spinner text font:
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:textColor="#FF0080FF"
android:popupBackground="#FF553232"
android:background="#FFD733D7"/>
But in the output, Color of text is always white.
Option 1. add your custom theme to style.xml. This will change the textcolor of items in the dropdown list.
<style name="MySpinnerTheme" parent="android:Theme">
<item name="android:textColor">#android:color/holo_green_dark</item>
</style>
layout
<Spinner
android:id="#+id/spinner1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/MySpinnerTheme"
android:spinnerMode="dropdown"/>
Option 2. If you want to change the selected item only.
...
Spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
...
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e){
Spinner spinner = (Spinner)sender;
TextView textView = (TextView)spinner.SelectedView;
textView.SetTextColor(Color.Rgb(0, 235, 0));
}
I'm working on Xamarin android. I want a spinner to show up on a button click or the spinner should be on top of a button, the other way I can say. Sounds crazy but that's the stuff I got in my head a couple of days back! Yeah I've seen Spinner. May be what I'm asking is not part of the plan, but I wanna implement that!
UPDATE 2: Let me explain with an example.
Consider the Web 2.0 scientific calculator. There is a button π. You long press the button and you will get a drop down. The constant that you select from the drop down will be displayed in the textbox. I want the same functionality with the spinner. Just the difference is I want it on the button click rather than a long press. Hope I'm clear now.
That's the part of code I tried with:
<!--main.axml-->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:id="#+id/myTitle">
<!--some stuff-->
<ImageButton android:onClick="onClick"
android:id="#+id/btnPi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:padding="100dip"
android:src="#drawable/pi" />
<Spinner
android:onClick="onClick"
android:id="#+id/btnConst"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".33"
android:prompt="#string/cons" />
<!--And few other stuffs-->
</LinearLayout>
<!--Strings.xml-->
<string name="cons">const</string>
<string-array name="ConsArray">
<item>Angstrom star</item>
<item>Faraday constant</item>
<item>Planck constant</item>
<item>Rydberg constant</item>
<item>Stefan-Boltzmann constant</item>
<item>electric constant</item>
<item>mag. constant</item>
<item>neutron mass</item>
</string-array>
It doesn't matter's to me whether I use a Button or a ImageButton ! I'm happy with either of it. Basically I just want a drop-down menu to popup, as soon as I click that button. Can anyone help me with this? Thanks in advance.
UPDATE: When I worked on York Shen's answer , I got this blank space occupied by the spinner:
I want a spinner to show up on a button click.
You could put a Button on Spinner by using a FrameLayout :
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="#+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:prompt="#string/planet_prompt"
/>
<Button
android:id="#+id/bt_spinner"
android:text="Spinner Button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</FrameLayout>
Then, every time your Button is click, you could use spinner.PerformClick() method to show your Spinner :
bt_spinner.Click += (sender, e) =>
{
spinner.PerformClick();
};
Effect.
Update :
I cant reproduce your problem, but here is my complete code from the document, you could use it and try again :
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.planets_array, Android.Resource.Layout.SimpleSpinnerItem);
adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = adapter;
bt_spinner.Click += (sender, e) =>
{
spinner.PerformClick();
};
...
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
string toast = string.Format("The planet is {0}", spinner.GetItemAtPosition(e.Position));
Toast.MakeText(this, toast, ToastLength.Long).Show();
}
In your XAML, set the spinner to not be visible. In your onClick event, set change the visibility. You may have to do more in onClick if you want the things below the spinner in the linear layout to move out of the way.
I am working on chat application where Edittext and send button is at bottom.
Activity is fullscreen, hidden navigation and status bar.
I need to push edittext and send button up when keyboard comes into focus.
I tried to set android:windowSoftInputMode="adjustResize" but it didn't worked.
I tried using AndroidBug5497Workaround.assistActivity(this) class referred from https://github.com/madebycm/AndroidBug5497Workaround but it didn't worked.
Below is my activity theme and code in activity to hide bar and make full screen :
decorView = getWindow().getDecorView();
uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
Theme :
<style name="AppTheme_DarkStatus" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryveryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowContentTransitions">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
XMl :
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/include_view"
android:isScrollContainer="true"
android:background="#android:color/white">
<com.handmark.pulltorefresh.library.PullToRefreshListView
xmlns:ptr="http://schemas.android.com/apk/res-auto"
android:id="#+id/lv_chat"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rl_send"
android:divider="#null"
android:fadeScrollbars="false"
android:fadingEdge="none"
android:overScrollMode="never"
android:scrollbars="none"
ptr:ptrHeaderSubTextColor="#color/c_input_text_color"
ptr:ptrHeaderTextColor="#color/c_input_text_color"
ptr:ptrOverScroll="false"
ptr:ptrPullLabel="Pull to refresh"
ptr:ptrRefreshLabel="Loading..."
ptr:ptrReleaseLabel="Release to refresh"
ptr:ptrRotateDrawableWhilePulling="true"
ptr:ptrShowIndicator="false" >
</com.handmark.pulltorefresh.library.PullToRefreshListView>
<RelativeLayout
android:id="#+id/rl_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/c_white"
android:gravity="center" >
<View
android:id="#+id/view_dummy"
android:layout_width="match_parent"
android:layout_height="#dimen/d_diff_p5dp"
android:background="#color/c_text_light_color" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view_dummy"
android:layout_toLeftOf="#+id/btn_send"
android:layout_marginRight="#dimen/d_diff_5dp"
android:layout_marginLeft="#dimen/d_diff_10dp"
android:layout_marginTop="#dimen/s_diff_7sp"
android:layout_marginBottom="#dimen/s_diff_7sp"
android:background="#drawable/opawhite_rectcorner_all" android:id="#+id/relativeLayout">
<EditText
android:id="#+id/et_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/d_diff_1dp"
android:background="#null"
android:focusableInTouchMode="true"
android:maxHeight="100dp"
android:hint="Type here..."
android:maxLength="150"
android:textSize="#dimen/s_diff_16sp"
android:padding="#dimen/s_diff_6sp"
android:textColorHint="#color/c_input_text_color"
android:textColor="#color/c_black" />
</RelativeLayout>
<Textview
android:id="#+id/btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/c_white"
android:text="Send"
android:padding="#dimen/d_diff_5dp"
android:layout_marginRight="#dimen/d_diff_5dp"
android:gravity="center"
android:textColor="#color/c_orange_main"
android:textSize="#dimen/s_diff_16sp"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</RelativeLayout>
I want to show edittext and send button above keyboard but it overlaps edittext.
Thanks!
The property android:windowSoftInputMode="adjustResize" doesn't work with full screen activity, you have to remove activity full screen flags in order to get advantage of adjust resize.
see this:
A fullscreen window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the window's softInputMode field; the window will stay fullscreen and will not resize.
I'm trying to solve problem:
TimeChartView should be scrolled (navigate) to specific X axis value after app startup.
I'm trying to use ChartView.scrollTo (X, 0) and mChartView.setX(X)
But it works not like it was to be expected.
It's looks like ChartView moved by itself in layout instead of scroll.
Where is my mistake? Any other more suitable solution for this case?
Here is my code:
1) layout
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:fillViewport="true"
android:background="#000000"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:layout_gravity="bottom"
android:gravity="bottom"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/chartx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFAA00" <---------- ORANGE PART OF SCREEN, u can see on screenshot
android:gravity="bottom"
android:orientation="horizontal"
android:scrollbars="horizontal" >
</LinearLayout>
</LinearLayout>
</ScrollView>
2) activity
lChart = (LinearLayout) mapV.findViewById(R.id.chartx);
if (mChartView != null) {
lChart.removeView(mChartView);
}
mChartView = ChartFactory.getTimeChartView(mapActivity, mDataset, mRenderer, "dd/MMM/yy");
mChartView.scrollTo(100, 0);
lChart.addView(mChartView, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mChartView.repaint();
3) Data
for (int i = 0; i < 90; i++) {
c.set(c.MILLISECOND, 0);
c.set(c.SECOND, 0);
c.set(c.MINUTE, 0);
c.set(c.HOUR, 0);
time_series.add(new Date(value + i*cTimeChart.DAY), 0);
}
Let's say we are adding 90 values but we want our scrollable ChartView will be opened (visible) on value 45.
That's what I want to get to.
Here my screenshot
https://dl.dropboxusercontent.com/u/42675740/Screenshot.png
background="#FFAA00" - Orange part of screen, looks like ChartView moved inside layout.
And what I'm expecting - dates should be scrolled instead of view moving.
BTW. I'm using achartengine-1.1.0