Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Create own custom Title Bar TitleBar with a Icon Android example


AD MOB

onCreate in MainActivity.java

    @Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.main.xml);
        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
}


You can add to titlebar different Views by xml file.
custom_title.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="//schemas.android.com/apk/res/android" android:id="@+id/screen"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical">
    <TextView android:id="@+id/left_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Some text" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
       
        android:src="@drawable/ic_launcher" />
    
</RelativeLayout>





custom-title-titlebar-android

397LW NO topic_id




AD

Další témata ....(Topics)


98

Activity Lifecycle if button Home pressed Android example | activity-lifecycle-if-button-home-pressed-android-example


If on Android emulator home button pressed.

// button home presssed
19:37:06.727: INFO/ActivityManager(60): Starting: 
Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] 
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher } from pid 60

19:37:06.807: INFO/onSaveInstanceState(339): onSaveInstanceState()
19:37:06.848: INFO/onPause(339): onPause()
19:37:07.968: INFO/onStop(339): onStop()


Diagram of Activity lifecycle if button HOME pressed

life_cycle_button_home_pressed
20

How set gray text to EditText Android example | how-set-gray-text-to-edittext-android-example


Example source code for Android development. How set gray text to EditText when EditText is blank.
Hint text to display when the text is empty.
In layout/main.xml insert to EditText row Attribute Name android:hint="Some text"


<EditText
        android:id="@+id/myEdit" 
	android:layout_height="wrap_content" android:layout_width="fill_parent"
        android:hint="Some text"
	android:singleLine="true"
</EditText>	



Programatically you can use method setHint:


// setHint(CharSequence hint) example
(EditText)findViewById(R.id.myEdit).setHint("My text");
// or int resId as method setHint(int resId) 
EditText myEdit = findViewById(R.id.myEdit);
myEdit.setHint(R.string.app_name);



338

Linkify TextView clickable phone number url adress | linkify-textview-clickable-phone-number-url-adress


android:autoLink="all"

 <!-- text1 automatically linkifies things like URLs and phone numbers. -->
  <TextView
            android:id="@+id/text1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:autoLink="all"
            android:text="@string/link_text_auto"
            />
274

Eclipse Error parsing the sdk Android | eclipse-error-parsing-the-sdk-android


[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Error parsing the sdk.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Failed to create C:\Program Files\android\sdk\add-ons.
[2013-07-06 16:10:29 - SDK Manager] [SDK Manager] Error: Unable to parse SDK content.

You have to create add-ons folder as admin of PC
131

Draw color line set stroke width Android basic example | draw-line-android-basic-example


Canvas, drawLine(), setStrokeWidth(), Paint, setAntiAlias(boolean), onDraw()

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}

	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}

		@Override
		protected void onDraw(Canvas canvas) {

			canvas.drawColor(Color.YELLOW);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStrokeWidth(4.5f);
			// opacity
			p.setAlpha(0x80); //
			// drawLine (float startX, float startY, float stopX, float stopY,
			// Paint paint)
			canvas.drawLine(0, 0, 40, 40, p);
			canvas.drawLine(40, 0, 0, 40, p);

		}

	}
}


Editace: 2013-12-09 13:08:46
Počet článků v kategorii: 397
Url:create-own-custom-title-titlebar-android-example

AD
11 Share
Share
Tweet