Android runtime change switch Activity theme
static boolean mbThemeLight = false;
@Override
public void onCreate(Bundle savedInstanceState) {
if(mbThemeLight)
setTheme(android.R.style.Theme_Light);
super.onCreate(savedInstanceState);
// bla bla bla..........
}
private void switchTheme(){
mbThemeLight = true;
this.recreate();
}
396LW NO topic_id
AD
Další témata ....(Topics)
How set rounded corners and own styles ActivityMy.java
\res\drawable\back_button_answer.xml
Button btn.setBackgroundResource(R.drawable.back_button_answer);
\res\drawable\back_button_answer.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="//schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners android:radius="10dip" />
<!-- background -->
<gradient
android:startColor="#D6D7D6"
android:centerColor="#E2E2E2"
android:centerY="0.75"
android:endColor="#D6D7D6"
android:angle="270"
/>
<stroke android:width="2dip" android:color="#fff"/>
</shape>
Samsung Galaxy Ace nejlepší cena od 4 500 KCZ Kč (únor.2012)
Samsung Galaxy Ace je chytrý telefon s operačním systémem Android.
Samsung Galaxy Ace je (22.února2012) 4. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Galaxy Ace je 3.5G smartphone nabízí i quad-band GSM. Displej je 3,5 palcový TFT kapacitní dotykový LCD HVGA s (320x480) rozlišením. K dispozici je také 5 megapixelový fotoaparát s LED bleskem. Je schopny zaznamenat video v rozlišení QVGA (320x240) a VGA s (640x480) rozlišením. Ace je dodáván s 1350mAh Li-Ion baterií. Ace běží s OS Android 2.2 Froyo a lze jej upgradovat na Android 2.3.6 Gingerbread.
Samsung Galaxy Ace photo pic image
Zdroj obrázku: wikipedia
Samsung Galaxy Ace je chytrý telefon s operačním systémem Android.
Samsung Galaxy Ace je (22.února2012) 4. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.
Galaxy Ace je 3.5G smartphone nabízí i quad-band GSM. Displej je 3,5 palcový TFT kapacitní dotykový LCD HVGA s (320x480) rozlišením. K dispozici je také 5 megapixelový fotoaparát s LED bleskem. Je schopny zaznamenat video v rozlišení QVGA (320x240) a VGA s (640x480) rozlišením. Ace je dodáván s 1350mAh Li-Ion baterií. Ace běží s OS Android 2.2 Froyo a lze jej upgradovat na Android 2.3.6 Gingerbread.
Samsung Galaxy Ace photo pic image

Zdroj obrázku: wikipedia
Call findViewById from onCreateView
res\layout
activity_main.xml
fragment_main.xml
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.containerMoje, new PlaceholderFragment()).commit();
}
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
if (container == null) {
return null;
}
TextView mText;
mText = (TextView)rootView.findViewById(R.id.idText);
mText.setText("Hello from fragment_main");
return rootView;
}
}
}
res\layout
activity_main.xml
<FrameLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:id="@+id/containerMoje"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cz.okhelp.autoskola.MainActivity"
tools:ignore="MergeRootFrame" />
fragment_main.xml
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android"
xmlns:tools="//schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cz.okhelp.autoskola.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/idText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Dil 3. HeadlinesFragment.java
V 1. dílu jsme se něco dozvěděli od XML souborech
V 2. dílu jsme rozebrali MainActivity.java
V tomto dílu si rozebereme záludnosti v HeadlinesFragment.java souboru.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html Pozorně si jej nastudujte.
V 1. dílu jsme se něco dozvěděli od XML souborech
V 2. dílu jsme rozebrali MainActivity.java
V tomto dílu si rozebereme záludnosti v HeadlinesFragment.java souboru.
Používáme příklad i zip porojekt z https://developer.android.com/training/basics/fragments/creating.html Pozorně si jej nastudujte.
package com.example.android.fragments;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle;
// pokud chceme aby byla aplikace spustitelná i v nižších verzích Androidu
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
// extends ListFragment důležité pro základní obsluhu ListView atd.
public class HeadlinesFragment extends ListFragment {
// zajistí zpětné odesílání zprav - zde zachytí kliknutí uživatele na položku
// v ListView - seznamu položek
OnHeadlineSelectedListener mCallback;
// pro odposlouchávání zpráv v ListView a odesílání do MainActivity.java
public interface OnHeadlineSelectedListener {
/**
funkce je volána onArticleSelected z HeadlinesFragment když uživatel
klikne na item v ListView - položku seznamu -
Tělo funkce je v MainActivity!!! Tam proběhnou potřebné úkony.
Například výměna fragmentů atd. */
public void onArticleSelected(int position);
}
/** Protože je HeadlinesFragment rozšířením (extends) ListFragment
používá funkci onCreate().
ArticleFragment extends Fragment bude používat onCreateView()
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Zde si pohlídáme verze Androidu a přiřadíme jim
// předdefinovanou šablonu XML souboru
// Je to důležité pokud chceme využívat více možností,
// které nové verze nabízejí
// například podbarvení vybrané položky seznamu
int layout = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
android.R.layout.simple_list_item_activated_1 : android.R.layout.simple_list_item_1;
// zde se vytovoří jednotlivé položky seznamu v ListView
// Pole vypadá takto:
// static String[] Headlines = {"Article One","Article Two"};
// položky tedy ponesou názvy ze String[] Headlines
// Teoreticky si menší pole položek můžete dát i sem pro jednodušší editaci
setListAdapter(new ArrayAdapter<String>(getActivity(), layout, Ipsum.Headlines));
}
@Override
public void onStart() {
super.onStart();
// Pokud se bude zobrazovat dual-panel
// (pro tablety, větší obrazovky)
// například je dobré
// když bude zvýrazněna vybraná položka setChoiceMode(ListView.CHOICE_MODE_SINGLE);
// Toto provádíme v onStart(), kdy máme přístup k listview
if (getFragmentManager().findFragmentById(R.id.article_fragment) != null) {
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
}
// onAttach() bude asi deprecated, tak můžete vyzkoušet
/*
@Override
public void onAttach(Context context) {
super.onAttach(context);
Activity a;
if (context instanceof Activity){
a=(Activity) context;
}
}
*/
// nebo pohledat něco na inetu
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// Zde přiřadíme odposlouchávání zprávy kliknutí na položku ListView
// a zpětnou vazbu s MainActivity.
// Pokud se to nepodaří, bude zaznamenáno a předáno dál chybové hlášení
try {
mCallback = (OnHeadlineSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
/** kliknuto na položku ListView */
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// long id se bude hodit například při obsluze sql.databází
// Upozorní - předá zprávu MainActivity.java, že uživatel
// klikl na položku a odešle i pozici v seznamu
mCallback.onArticleSelected(position);
// getListView().setItemChecked(position, true);
// má zajistit podbarvení
// - zvýraznění vybrané položky,
// ale mi to nefungovalo, tak jsem ještě znovu přidal,
// které je už v onStart() a už to funguje jak má
// Možná nějaká záludnost v mém telefonu :(
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setItemChecked(position, true);
}
}
ScrollTo(), getTop(), getBottom(), getLeft(), getRight(), ScrollView, LinearLayout Android Java xml example.
How get position of a View.
MainClass.java
main.xml
How get position of a View.
MainClass.java
/*
public void scrollTo (int x, int y)
Since: API Level 1
Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.
This version also clamps the scrolling to the bounds of our child.
Parameters
x the x position to scroll to
y the y position to scroll to
*/
// sroll to top of hscrollViewMain
ScrollView hscrollViewMain = (ScrollView)findViewById(R.id.scrollViewMain);
hscrollViewMain.scrollTo(0, 0); // scroll to application top
// get position of a View
EditText hEdit = (EditText)findViewById(R.id.username_edit);
int nY_Pos = hEdit.getTop(); // getBottom(); X_pos getLeft(); getRight();
// scroll to top of hEdit
hscrollViewMain.scrollTo(0,nY_Pos);
main.xml
<LinearLayout
xmlns:android="//schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ScrollView
android:id="@*id/scrollViewMain"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:paddingTop="5dip"
android:paddingBottom="13dip"
android:paddingLeft="20dip"
android:paddingRight="20dip">
<TextView
android:id="@+id/message"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip" />
<TextView
android:textAppearance="?android:attr/textAppearanceSmall"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login_activity_username_label" />
<EditText
android:id="@+id/username_edit"
android:singleLine="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minWidth="250dip"
android:scrollHorizontally="true"
android:capitalize="none"
android:autoText="false"
android:inputType="textEmailAddress" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Editace: 2017-04-22 10:52:43
Počet článků v kategorii: 396
Url:android-runtime-change-switch-activity-theme