네, 제가 무지 쉬운걸 놓치고 몇시간 방황한 그 주제를 가지고 포스팅해보겠습니다.
액션바가 뭐나면요
여기 myTitle 적힌 부분입니다.
대부분 제목이 왼쪽 정렬되있을텐데요.
꾸며보고 싶지 않으세요?
이제부터 꾸며 봅시다.
[custom_bar.xml]
<?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="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textColor="#ffffff"
android:id="@+id/mytext"
android:textSize="22sp" />
</LinearLayout>
마치 액션바를 하나의 도화지로 보고 거기다 추가해주시면 됩니다.
아이콘을 넣을려면 ImageView 등을 쓰시면 되겠네요.
그후
[MainActivity.java]
import android.support.v7.app.ActionBar;public class MainActivity extends AppCompatActivity {@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_bar);
} catch (Exception e) {
System.out.println(e.getMessage());
}
setContentView(R.layout.activity_main);
네 일단 저 import를 꼭 해주시고요
그후
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.custom_bar);
이 두 문장을 onCreate 바로아래에 추가해주시면 완료~
'프로그래밍 > 앱프로그래밍' 카테고리의 다른 글
Google I/O 2017 Extended Seoul 짧은 소감 (0) | 2017.07.04 |
---|---|
안드로이드 강좌 - 토스트메시지의 시간을 조절하고 싶을때 #countdowntimer (0) | 2016.01.30 |
안드로이드 강좌 1. 버튼에 이미지 넣기 #ImageButton (0) | 2016.01.30 |
앱이름 한글로 하기 (0) | 2016.01.30 |
안드로이드 스튜디오 강좌 - 유용한 단축키 (0) | 2016.01.29 |