android backgroun does not change - android

I want my program to have the background color #222222. My graphical editor in eclipse shows me that it has this color but when I start the app on my device it has still a white background.
<?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:background="#222222" >
</LinearLayout>
in my PlaylistFragment.java :
//This is the fragment which uses this layout
public class PlaylistFragment extends Fragment {
#Override
public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ){
return inflater.inflate(R.layout.fragment_playlist, container, false);
}
}

Related

How to get rid of unwanted margin of DatePicker widget (Android)?

I am starting to learn how to develop android apps, more precisely I in trying to make an activity which host a single fragment (that extends DialogFragment) which in turn host a DatePicker Widget. I would like that DatePicker fill all screen width.
The problem is that for an unknown reason it puts a margin in the right of the screen (I want to get rid of the blank space).
This is what i get:
This is DatePicker layout:
<DatePicker
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialog_date_date_picker"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:calendarViewShown="false"/>
This is the activity's layout that host the fragment:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
And this is the fragment code:
public class DatePickerFragment extends DialogFragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_date, container, false);
return view;
}
}
Notice that I don't want to use 'onCreateDialog', in this particular case I want to use 'onCreateView'.

ListView on Fragment does not appear

I have made a ListView on a Fragment.
public class MyList extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.mylist, container, false);
return view;
}
}
This is the xml file where is the ListView:
<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.view.BoxInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ddffff"
xmlns:app="http://schemas.android.com/apk/res-auto"
>>
<android.support.wearable.view.WearableListView
android:id="#+id/mylist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="none"></android.support.wearable.view.WearableListView>
</android.support.wearable.view.BoxInsetLayout>
When I run my app the listview does not appear. The entire screen is black. What I want to know is why this is happening.
Because of the typo in the following line:
xmlns:app="http://schemas.android.com/apk/res-auto"
>>
It cannot read >>. Android doesn't throw an exception for this typo

Using Clock-Widget in a Fragment possible?

I have a Fragment in my MainActivity, that displays a Digital Clock. It works: It shows the current system time. But it looks rather simple. So before I start trying to style this clock I wanted to ask, if there is a way, to use the systems Digital-Clock Widget?
Screenshot of the widget, that I'd like to use in my Fragment:
FragmentClock.java:
public class FragmentClock extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = inflater.inflate(R.layout.fragment_clock, container, false);
return view;
}
}
fragment_clock.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/LinearLayoutClockDisplay"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#000000">
<DigitalClock
android:id="#+id/digital_clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"/>
</LinearLayout>

Android dashboard pattern as fragment

Is is possible to use the android dashboard pattern from Google I/O as a fragment so that in landscape mode on a tablet the dashboard is shown on the left while the content of the current category is shown on the right?
I've tried something that looks like the code below but it doesnt work.
main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Include dashboard -->
<include layout="#layout/fragment_dashboard"/>
<!-- Include details -->
<fragment
android:id="#+id/fragment_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.example.fragments.Details" />
</LinearLayout>
Details.java:
public class Details extends Fragment
{
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.details, container, false);
return view;
}
}

Different fragment wasn`t loaded when orientation changed (android)

I created a test project that has two different fragments to be shown in the same activity. One fragment is for landscape and the other for portrait.
# My unique activity
public class MainActivity extends FragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
# First Fragment
public class LandscapeFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TextView v = (TextView) inflater.inflate(R.layout.fragment, container, false);
v.setText("LANDSCAPE");
return v;
}
}
# Other Fragment
public class PortraitFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
TextView v = (TextView) inflater.inflate(R.layout.fragment, container, false);
v.setText("PORTRAIT");
return v;
}
}
And I have two main.xml, one in layout/ and the other in layout-land/. Each main.xml points to the correct Fragment to be used.
<!-- layout-land/main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment"
android:name="br.luckcheese.test.LandscapeFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
<!-- layout/main.xml -->
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment"
android:name="br.luckcheese.test.PortraitFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp" />
<!-- layout/fragment.xml -->
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30sp" />
When I open the app on landscape the LandscapeFragment is shown, and when I open in Portrait the PortraitFragment is shown. So far, so good.
But if I open in landscape and rotate the device to portrait then the LandscapeFragment is reloaded and shown.
Which is not the predicted behavior. The PortraitFragment should have been loaded.
And the same thing happens the other way around, if the device starts at the portrait orientation and then I rotate it to landscape: the PortraitFragment just gets reloaded, instead of having the LandscapeFragment loaded.
What am I doing wrong?
Make sure that you don't have: android:config="orientation" in your manifest.xml
The problem is in your 2 layouts, the fragment ids are the same.
Just change these fragment ids, like :
fragmentportrait for layout/main.xml
fragmentlanscape for layout-land/main.xml.
(And change also:
Fragment frag = getSupportFragmentManager().findFragmentById(R.id.fragment);
frag.setRetainInstance(false);
)

Categories

Resources