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 tagandroid: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:showAsAction
This 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); } }
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:andro xmlns:app="/apk/res-auto"> <!-- Add hiddenAction item --> <item android: android:icon="@drawable/search" android:title="search" app:showAsAction="always" /> </menu>
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); } }
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:andro xmlns:app="/apk/res-auto"> <!-- v7 In-house components --> <!-- Searched Action View --> <item android:id= "@+id/search" android:title="search" app:actionViewClass="." app:showAsAction="always" /> </menu>
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
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:andro package=""> <uses-permission android:name=".CALL_PHONE"></uses-permission> <uses-permission android:name=".SEND_SMS"></uses-permission> <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"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="" /> <category android:name="" /> </intent-filter> </activity> <activity android:name=".FriendsActivity" android:label="Friends" <!-- Here is aAction item It's the name-- > > <!-- Specify the current activity The fatheractivity--> <meta-data android:name=".PARENT_ACTIVITY" android:value=".MainActivity"></meta-data> </activity> </application> </manifest>
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 } }); } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:andro xmlns:tools="/tools" android: android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/background" tools:context=".MainActivity"> <!-- Add to Moments ImageButtonof --> <ImageButton android: android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/button" android:scaleType="fitXY" android:layout_marginTop="@dimen/marginTop"></ImageButton> </RelativeLayout>
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!