[Android] Notes on xml

RelativeLayout --If you use toEndOf etc. in RelativeLayout, It can be side by side even if it is not LinearLayout. --Center Horizontal (true) of RlativeLayout can be used for centering.

EditText
--If you want to enter characters in the placeholder, use hint.

hoge.xml



<EditText
 android:id="@+id/login"
 android:layout_width="200dp"
 android:layout_height="40dp"
 android:hint="@string/login"
 android:textColor="@color/white"
 android:textColorHint="@color/clear_white" />

Centered

--If center_vertical does not work, set layout_gravity to center.

Area division

--When you want to place two same views side by side: set layout_weight: 1 and set Width = 0. --When you want to place two same views vertically: set layout_weight: 1 and set Height = 0.

I want to make something like a tab

--Use ViewPager / PagerTitleStrip.

Centered characters

--Set gravity = center.

Round the button

--Create shape.xml separately in drawable and refer to it in the background of view.

shape.xml


<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!--Border width:Line width, color:Line color-->
    <stroke
        android:width="0.6dp"
        android:color="@color/white" />

</shape>

Invert the text color by pressing (white → black)

--Create a selector in hoge.xml of drawable and refer to it with textColor.

hoge.xml


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:s="true" android:state_pressed="false" android:color="@color/black" />
        <item android:state_focused="true" android:state_pressed="true" android:color="@color/black" />
        <item android:state_focused="false" android:state_pressed="true" android:color="@color/black" />
        <item android:color="@color/white" />

</selector>

Replace the image by pressing (active color image → inactive color image)

--Create a selector in huga.xml of drwable and refer to it in src.

huga.xml


<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!--Pressed state-->
    <item
        android:state_pressed="true"
        android:drawable="@drawable/setting_click" />
    <!--Normal state-->
    <item
        android:drawable="@drawable/setting" />
</selector>

Recommended Posts

[Android] Notes on xml
Notes on calling Installer on Android App
Notes on Android (java) thread processing
[Android] Detailed notes
Notes on creating android plugins for Unity
Notes on Protocol Buffers
Notes on getting Callback from Android text-to-speech function TextToSpeech
python notes on docker
Notes on multiple inheritance
[Android / Kotlin] Detailed notes 2
Notes on regular expressions
Notes in Android studio
Customize list view on Android
Multipart transmission library on Android
Use serial communication on Android
ROS app development on Android
Use native code on Android
[Ruby] Notes on gets method
Event handling with RxBus on Android
How to "hollow" View on Android
[Android] Get the date on Monday
Get JUnit code coverage on Android.
Notes for Android application development beginners
Watson Assistant (formerly Conversation) on Android
Notes on signal control in Java
Save ArrayList using GSON on Android
Notes on migrating from CircleCI 1.0 to 2.0
[Android] Receive intent on Broadcast Reciever
Notes on Java path and Package
Implement ripple representation on images on Android
Speed up location acquisition on Android
Notes on handling UTF-8 encoded property files
Try using the service on Android Oreo
Asynchronous processing by RxJava (RxAndroid) on Android
How to detect microphone conflicts on Android
Calling java from C ++ on Android NDK
Notes on operators using Java ~ String type ~
Output Notes document as XML document in Java
[Adult free study] Acoustic communication on Android
Sobel filter using OpenCV on Android (Java)
Notes on expand () and collapse () of Expandablerecyclerview
Notes on using FCM with Ruby on Rails
[Android] Let's snoop on other people's apps
I made a calculator app on Android
Notes on Java's Stream API and SQL
Notes on JSP extension tags in SpringFrameWork
Allows Youtube autoplay on Cordova's Android app