test는 아래 기기에서 진행함.
samsung note 8 (android 9)
xiaomi redmi 9 (android 11)
기본 코드
AndroidManifest.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | < code ><? xml version = "1.0" encoding = "utf-8" ?> < manifest xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:tools = "http://schemas.android.com/tools" package = "com.norang.autoactionbar" > < uses-permission android:name = "android.permission.INTERNET" /> <!-- 인터넷 퍼미션 --> < uses-permission android:name = "android.permission.ACCESS_NETWORK_STATE" /> < application android:allowBackup = "true" android:dataExtractionRules = "@xml/data_extraction_rules" android:fullBackupContent = "@xml/backup_rules" android:icon = "@mipmap/ic_launcher" android:label = "@string/app_name" android:networkSecurityConfig = "@xml/network_security_config" android:roundIcon = "@mipmap/ic_launcher_round" android:supportsRtl = "true" android:theme = "@style/Theme.AutoActionBar" android:usesCleartextTraffic = "true" tools:targetApi = "31" > < activity android:name = ".a_text" android:exported = "false" /> < activity android:name = ".a_web" android:exported = "false" /> < activity android:name = ".MainActivity" android:exported = "true" > < intent-filter > < action android:name = "android.intent.action.MAIN" /> < category android:name = "android.intent.category.LAUNCHER" /> </ intent-filter > </ activity > </ application > </ manifest > </ code > |
build.gradle
-----------------------------------------------------------------------------------------------------------
plugins {
id 'com.android.application'
}
android {
compileSdk 32
defaultConfig {
applicationId "com.norang.autoactionbar"
minSdk 28
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//BottomNavigationView(하단 바 생성)
implementation "com.google.android.material:material:1.2.1"
//BottomNavigationView(하단 바 생성)
}
-----------------------------------------------------------------------------------------------------------
network_security_config.xml
웹으로 스크롤 할 것 아니면 필요없음.
textview나 list로 할 경우는 없어도 됨.
1 2 3 4 5 6 7 8 9 10 11 12 13 | < code > <? xml version = "1.0" encoding = "utf-8" ?> < network-security-config > < domain-config cleartextTrafficPermitted = "true" > < domain includeSubdomains = "true" >m.naver.com</ domain > < domain includeSubdomains = "true" >www.naver.com</ domain > < domain includeSubdomains = "true" >www.daum.net</ domain > < domain includeSubdomains = "true" >www.google.com</ domain > < domain includeSubdomains = "true" >www.amazon.com</ domain > < domain includeSubdomains = "true" >www.11st.co.kr</ domain > </ domain-config > </ network-security-config > </ code > |
themes.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | < code > < resources xmlns:tools = "http://schemas.android.com/tools" > <!-- Base application theme. --> < style name = "Theme.AutoActionBar" parent = "Theme.MaterialComponents.DayNight.DarkActionBar" > <!-- Primary brand color. --> < item name = "colorPrimary" >@color/purple_500</ item > < item name = "colorPrimaryVariant" >@color/purple_700</ item > < item name = "colorOnPrimary" >@color/white</ item > <!-- Secondary brand color. --> < item name = "colorSecondary" >@color/teal_200</ item > < item name = "colorSecondaryVariant" >@color/teal_700</ item > < item name = "colorOnSecondary" >@color/black</ item > <!-- Status bar color. --> < item name = "android:statusBarColor" tools:targetApi = "l" >?attr/colorPrimaryVariant</ item > <!-- Customize your theme here. --> < item name = "windowActionBar" >false</ item > < item name = "windowNoTitle" >true</ item > </ style > </ resources > </ code > |
up_navigation_menu.xml
상단 바 버튼 메뉴
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | < code > <? xml version = "1.0" encoding = "utf-8" ?> < menu xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:app = "http://schemas.android.com/apk/res-auto" > < item android:id = "@+id/btnTb01" android:icon = "@drawable/ic_test01" android:title = "notification" app:showAsAction = "always" /> < item android:id = "@+id/btnTb02" android:title = "app_bar_search" app:actionLayout = "@layout/badge_layout" app:showAsAction = "always" /> < item android:id = "@+id/btnTb03" android:icon = "@drawable/ic_baseline_settings_24" android:title = "app_bar_search" app:showAsAction = "always" /> </ menu > </ code > |
botom_navigation_menu.xml
하단바 버튼 메뉴
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | < code > <? xml version = "1.0" encoding = "utf-8" ?> < menu xmlns:android = "http://schemas.android.com/apk/res/android" > < item android:id = "@+id/page_1" android:enabled = "true" android:icon = "@drawable/ic_baseline_auto_delete_24" android:title = "test1" /> < item android:id = "@+id/page_2" android:enabled = "true" android:icon = "@drawable/ic_ico_bottom_02" android:title = "test2" /> < item android:id = "@+id/page_3" android:enabled = "true" android:icon = "@drawable/ic_ico_bottom_03" android:title = "test3" /> < item android:id = "@+id/page_4" android:enabled = "true" android:icon = "@drawable/ic_ico_bottom_04" android:title = "test4" /> < item android:id = "@+id/page_5" android:enabled = "true" android:icon = "@drawable/ic_ico_bottom_05" android:title = "test5" /> </ menu > </ code > |
MainActivity
웹뷰랑 텍스트뷰 샘플 이동을 위한 것으로 없어도 됨.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | <code> public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super .onCreate(savedInstanceState); setContentView(R.layout.activity_main); permission(); } public void btnButtonClick(View view) { Intent intent = null ; Intent serviceIntent = null ; switch (view.getId()) { case R.id.btnWeb: intent = new Intent(getApplicationContext(), a_web. class ); startActivity(intent); break ; case R.id.btnText: intent = new Intent(getApplicationContext(), a_text. class ); startActivity(intent); break ; } } //@TargetApi(Build.VERSION_CODES.M) public void permission() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { if (checkSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) { requestPermissions( new String[]{ Manifest.permission.INTERNET, Manifest.permission.ACCESS_NETWORK_STATE, }, 1 ); } } else { if (checkSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED || checkSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE) != PackageManager.PERMISSION_GRANTED) { requestPermissions( new String[]{ Manifest.permission.INTERNET, Manifest.permission.ACCESS_NETWORK_STATE}, 1 ); } } } //권한 획득 여부에 따른 결과 반환 @Override public void onRequestPermissionsResult( int requestCode, @NonNull String[] permissions, @NonNull int [] grantResults) { super .onRequestPermissionsResult(requestCode, permissions, grantResults); } } </code> |
activity_main.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | < code > <? xml version = "1.0" encoding = "utf-8" ?> < androidx.constraintlayout.widget.ConstraintLayout xmlns:android = "http://schemas.android.com/apk/res/android" xmlns:app = "http://schemas.android.com/apk/res-auto" xmlns:tools = "http://schemas.android.com/tools" android:layout_width = "match_parent" android:layout_height = "match_parent" tools:context = ".MainActivity" > < LinearLayout android:layout_width = "match_parent" android:layout_height = "match_parent" android:layout_gravity = "right|top" android:orientation = "vertical" tools:ignore = "MissingConstraints" > < Button android:id = "@+id/btnWeb" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:onClick = "btnButtonClick" android:text = "web" /> < Button android:id = "@+id/btnText" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:onClick = "btnButtonClick" android:text = "textview" /> </ LinearLayout > </ androidx.constraintlayout.widget.ConstraintLayout > </ code > |
'Android' 카테고리의 다른 글
android floating Action bar & Bottom Navigation View(4) (4) | 2022.08.01 |
---|---|
android floating Action bar & Bottom Navigation View(3) (294) | 2022.08.01 |
android floating Action bar & Bottom Navigation View(1) (1) | 2022.07.16 |
SharedPreferences 사용법 (2) | 2021.11.29 |
LinearLayout (6) | 2021.11.29 |
댓글