1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.apis.app; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.view.View; 22 import android.view.Window; 23 import android.view.View.OnClickListener; 24 import android.widget.Button; 25 import android.widget.EditText; 26 import android.widget.TextView; 27 28 import com.example.android.apis.R; 29 30 31 /** 32 * Example of how to use a custom title {@link android.view.Window#FEATURE_CUSTOM_TITLE}. 33 * <h3>CustomTitle</h3> 34 35 <p>This demonstrates how a custom title can be used.</p> 36 37 <h4>Demo</h4> 38 App/Title/Custom Title 39 40 <h4>Source files</h4> 41 * <table class="LinkTable"> 42 * <tr> 43 * <td >src/com.example.android.apis/app/CustomTitle.java</td> 44 * <td >The Custom Title implementation</td> 45 * </tr> 46 * <tr> 47 * <td >/res/any/layout/custom_title.xml</td> 48 * <td >Defines contents of the screen</td> 49 * </tr> 50 * </table> 51 */ 52 public class CustomTitle extends Activity { 53 54 /** 55 * Initialization of the Activity after it is first created. Must at least 56 * call {@link android.app.Activity#setContentView(int)} to 57 * describe what is to be displayed in the screen. 58 */ 59 @Override 60 protected void onCreate(Bundle savedInstanceState) { 61 super.onCreate(savedInstanceState); 62 63 requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 64 setContentView(R.layout.custom_title); 65 getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_1); 66 67 final TextView leftText = (TextView) findViewById(R.id.left_text); 68 final TextView rightText = (TextView) findViewById(R.id.right_text); 69 final EditText leftTextEdit = (EditText) findViewById(R.id.left_text_edit); 70 final EditText rightTextEdit = (EditText) findViewById(R.id.right_text_edit); 71 Button leftButton = (Button) findViewById(R.id.left_text_button); 72 Button rightButton = (Button) findViewById(R.id.right_text_button); 73 74 leftButton.setOnClickListener(new OnClickListener() { 75 public void onClick(View v) { 76 leftText.setText(leftTextEdit.getText()); 77 } 78 }); 79 rightButton.setOnClickListener(new OnClickListener() { 80 public void onClick(View v) { 81 rightText.setText(rightTextEdit.getText()); 82 } 83 }); 84 } 85 } 86