Changing xml or layout during runtime - java

on my Android project I need to change the color of a xml property: app:footerColor="#1573D6" dynamically during runtime. How can I achieve this?
I could change the layout too during the running of the App, but I looked for how to do it and couldn't find anything.
Some help would be great. Thank you very much.
Here's my xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.viewpagerindicator.TitlePageIndicator
android:id="#+id/tabloid"
android:padding="10dip"
android:layout_height="40dp"
android:layout_width="fill_parent"
android:background="#000000"
android:textColor="#1573D6"
app:footerColor="#1573D6"
app:footerLineHeight="2dp"
app:footerIndicatorStyle="none"
app:selectedColor="#FFFFFF"
app:selectedBold="true" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />

you can do this in code:
TitlePageIndicator indicator =(TitlePageIndicator)findViewById(R.id.yourview)
indicator.SetFooterColor(Color.parse( #1573D6))

Related

How to achieve this layout in android in a TextView and ScrollView

Can anyone please tell me how I can achieve this? It will display a lot of scrollable text so I think that I am off to the right start. It will be dynamic and be able to be created at runtime.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:layout_editor_absoluteX="0"
tools:layout_editor_absoluteY="0">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="50dp"
android:layout_height="fill_parent"
android:background="#477046">
<TextView
android:id="#+id/txtViewLeft"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18dp"
android:text="A1" />
</ScrollView>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#468490"
android:layout_toRightOf="#id/scrollView1">
<TextView
android:id="#+id/txtViewRight"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18dp"
android:text="This is some sample text that I have added. Thank you for helping" />
</ScrollView>
</RelativeLayout>
Any help you can give is greatly appreciated. Thanks

RelativeLayout doesn't meet it's on height

I trying to create a relative layout that look like toolbar but I keep on having such height problem as shown below:
What I want is:
Here's my code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/Searchtoolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:background="#color/Toolbar_default_color"
android:minHeight="?attr/actionBarSize">
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:layout_below="#+id/Searchtoolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/FilterLayout"
android:layout_width="match_parent"
android:layout_height="40dp">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/search_filter_icon"
android:background="#drawable/search_filter_bgn_btn"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
<ListView
android:id="#+id/feed_listview"
android:layout_below="#+id/FilterLayout"
android:layout_marginTop="?attr/actionBarSize"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null" />
</RelativeLayout>
</RelativeLayout>
In your ImageButton use: android:layout_height="match_parent"
instead of android:layout_height="wrap_content"
Or resize your Image using photoshop or any other free tool to fit 40dp exactly.
WRAP_CONTENT: which means that the view wants to be just big enough to enclose its content (plus padding)
What you need:
MATCH_PARENT: which means that the view wants to be as big as its parent (minus padding)
Documentation.
I found my bad and silly mistake. It was the "android:layout_marginTop="?attr/actionBarSize" under the listview that causes the white layout to be extended. After I removed that line, I got what I wanted. =)

Analog Clock does not appear in the application

I'm trying to set a analog clock for my app but both the analog clock and the digital clock just dont appear when i run the app on my device, but if i look at the graphic view of the layout its there!
Heres my code:
<?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="100" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="30" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
//Some Text Views and Edit Texts here!
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="20" >
<Space
android:layout_width="match_parent"
android:layout_height="2dp" />
<Button
android:text="Send"
android:id="#+id/bSendEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="50" >
<Space
android:layout_width="match_parent"
android:layout_height="2dp" />
<AnalogClock
android:id="#+id/acClock"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
My guess is that your layout is not scaling well to varied resolutions. Click the Preview All Screens option (in in the Graphical Layout section of Eclipse) to see if you can see the same cropping problem there. If so, you'll need to experiment with different layout weights, etc. to ensure that the layout works well across different device resolutions.
I guess problem can be about ScrollView. Try to change it and let me know result. Because I don't know for which reason its happening but sometimes with ScrollView view is getting hidden...

Change recent layout android

i would try to change the system recent app layout in a custom rom. Actually, in android stock, we have a simple vertical scrollable column with recent apps.. I would change it and make a gridview like LG --> http://www.androidcentral.com/sites/androidcentral.com/files/styles/large_wm_brw/public/article_images/2014/07/task-switchers.jpg?itok=DQwWAMpQ it's not so easy and i need help.. i have some question;
1) Change the xml only is enought?
2) Have i to change the adapter too in java or something else in java code?
The xml is this one:
<?xml version="1.0" encoding="utf-8"?>
<com.android.systemui.recent.RecentsPanelView
android:id="#id/recents_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:foreground="#drawable/bg_protect"
systemui:recentItemLayout="#layout/status_bar_recent_item"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:systemui="http://schemas.android.com/apk/res/com.android.systemui">
<FrameLayout android:id="#id/recents_bg_protect"
android:background="#drawable/status_bar_recents_background"
android:fitsSystemWindows="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<com.android.systemui.recent.RecentsVerticalScrollView
android:layout_gravity="top|left|center"
android:id="#id/recents_container"
android:scrollbars="none"
android:fadingEdge="vertical"
android:fadingEdgeLength="#dimen/status_bar_recents_scroll_fading_edge_length"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stackFromBottom="true"
android:divider="#null"
android:layout_marginEnd="0.0dip">
<LinearLayout
android:id="#id/recents_linear_layout"
android:fitsSystemWindows="true"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</com.android.systemui.recent.RecentsVerticalScrollView>
<ImageView
android:layout_gravity="bottom|left|center"
android:id="#id/recents_clear"
android:clickable="true"
android:layout_width="50.0dip"
android:layout_height="50.0dip"
android:src="#drawable/ic_notify_clear"
android:scaleType="center" />
</FrameLayout>
<include android:id="#id/recents_no_apps" android:visibility="invisible" android:layout_width="fill_parent" android:layout_height="fill_parent" layout="#layout/status_bar_no_recent_apps" />
</com.android.systemui.recent.RecentsPanelView>
The class RecentsPanelView extends a FrameLayout.. i tried simple change and extends a gridview but without any changes.. i think it was too much easy just change this point.. However, actually with this xml i can display in horizontal the recent apps but only in one row.. Any idea? Maybe adding a gridview in this layout?

If I use weight layout, then my Java file cannot find the view by id

I have an XML layout using weight layout like this.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
In my Java file, I do like this, then my app crashes. If I don't use the weight layout, everything works fine.
WebView wv = (WebView) findViewById(R.id.webView1);
I think everything is fine. If you are using eclipse then Go to project -> clean and clean your project. then try to run or else restart your adb and eclipse. Then try to run.
The app works if I switch the webview and viewpage position like 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:weightSum="2"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
</LinearLayout>
Try to set height for both of the controls as match_parent instead of 0dp

Categories