SoFunction
Updated on 2025-04-09

Extra detailed explanation of Android resource files and hierarchical navigation

Android's own resources

String resources:

  • Define string resources in < >;
  • Use string resources in JAVA, get the resource through getResource().getString(), and load it dynamically into the textView text box.
TextView textview = findViewById();
(getResource().getString());

2. Color resources

# Transparency RGB Transparency is generally 4 digits

dimen represents the size resource, set the spacing of the grid

drawable resources:

Image Resource 2. stateListDrawable Resource

*. : It is an automatically scalable picture under Android. Set the scalable area of ​​png to make the fixed image in the picture not distorted. There is a

Note that you cannot use capital letters when pictures

SateListDrawable :

1. Lost focus and converge focus Use selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:andro>
    <item android:state_focused="true" android:color="#f60"></item>
</selector>

Action Bar

1. Provide quick functions but save layout space, such as product classification on Taobao interface

Hide and show Action bar:

1. Add a corresponding activity tag
android:theme="@style/"
The above method is static display control Action Bar
2. Dynamic Hide or show Action Bar
3. ActionBar actionBar = getSupportActionBar()

 (new ViewObClick() {
	public void onClick(View v ){
 		();
 }
})

Action Item

  • Define menu resource files
  • Load the menu resource file in the OnCreateOptionsMenu() method

Attention Medium Keyapp:showAsActionThis control has four properties

always, ifRoom, never means whether the Action Item will be displayed in the navigation bar. IfRoom means that it can be displayed if there is, and if there is no, it will be hidden. The last Action Item usually uses the never role:

package ;
import ;
import ;
import ;
import ;
/**
   * Action Item display
  */
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Rewrite this method Reload        MenuInflater inflater = getMenuInflater();
        //Analysis menu        (, menu);
        return (menu);
    }
}
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:andro
    xmlns:app="/apk/res-auto"&gt;
        &lt;!--  Add hiddenAction item  --&gt;
        &lt;item android:
            android:icon="@drawable/search"
            android:title="search"
            app:showAsAction="always"
            /&gt;
&lt;/menu&gt;

Action View

The component with search function on the Action Bar is called Action View

Add some components for Action view search on the Action Bar

package ;
import ;
import ;
import ;
import ;
/**
   * Gesture mode sliding animation
  */
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
        // Hide Action Bar Show Title        getSupportActionBar().setDisplayShowTitleEnabled(false);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Rewrite this method Reload        MenuInflater inflater = getMenuInflater();
        //Analysis menu        (, menu);
        return (menu);
    }
}
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;menu xmlns:andro
    xmlns:app="/apk/res-auto"&gt;
        &lt;!--  v7 In-house components          --&gt;
        &lt;!-- Searched Action View --&gt;
        &lt;item android:id= "@+id/search"
             android:title="search"
             app:actionViewClass="."
             app:showAsAction="always"
            /&gt;
&lt;/menu&gt;

Summary Add Action View

The first type: app:actionViewClass: -> Implementation class (with Android, custom)

The second type: app:actionLayout -> Layout file *.xml

Implement hierarchical navigation

  • Layout interface creates FriendsActivity
  • Determine whether the parent activity is empty, and return to navigation display if it is not empty.
  • Configure parent activity for FriendActivity (requires description parent activity in
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;manifest xmlns:andro
    package=""&gt;
    &lt;uses-permission android:name=".CALL_PHONE"&gt;&lt;/uses-permission&gt;
    &lt;uses-permission android:name=".SEND_SMS"&gt;&lt;/uses-permission&gt;
    &lt;application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"&gt;
        &lt;activity android:name=".MainActivity"&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="" /&gt;
                &lt;category android:name="" /&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
       &lt;activity android:name=".FriendsActivity"
                android:label="Friends" &lt;!-- Here is aAction item It's the name-- &gt;
           &gt;
&lt;!--           Specify the current activity The fatheractivity--&gt;
           &lt;meta-data android:name=".PARENT_ACTIVITY"
               android:value=".MainActivity"&gt;&lt;/meta-data&gt;
       &lt;/activity&gt;
    &lt;/application&gt;
&lt;/manifest&gt;
package ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
/**
   * Gesture mode sliding animation
  */
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_main);
        ImageView imageView= (ImageView) findViewById(); //Get pictures of Moments        (new () { //Set click events for the picture            @Override
            public void onClick(View v) {
                Intent intent=new Intent(,); //Create an Intent object                startActivity(intent); //Start Activity            }
        });
    }
}
&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;RelativeLayout
    xmlns:andro
    xmlns:tools="/tools"
    android:
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    tools:context=".MainActivity"&gt;
&lt;!--   Add to Moments ImageButtonof --&gt;
&lt;ImageButton
    android:
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/button"
    android:scaleType="fitXY"
    android:layout_marginTop="@dimen/marginTop"&gt;&lt;/ImageButton&gt;
&lt;/RelativeLayout&gt;
package ;
import ;
import ;
import ;
public class FriendsActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        (savedInstanceState);
        setContentView(.activity_friends);
        //Get whether the parent activity is empty        if(() != null){
            getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:andro
    xmlns:tools="/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg"
    tools:context=".FriendsActivity">
</RelativeLayout>

This is the article about this detailed explanation of Android resource files and hierarchical navigation. For more related Android resource files, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!