Mystery Activity Does Not Conform to App Theme - android

after months of developing on the Android platform, I still have an unanswered question. I noticed a long time ago that I have ONE single Activity that doesn't conform to the rest of the app theme. This means that by default, the font color of the Activity is white (not black), and Checkboxes don't show up when not checked, you can't see them at all. Very peculiar behavior. Recently, I changed the colorAccent attribute of my theme, which changed ALL accent colors to orange (including Checkboxes), but this Activity remains unchanged. Has anybody ever experienced this?
I made this Activity into a fragment once, and it then magically conformed to the theme. After switching back to the Activity, even making a brand new Activity to host the logic, nothing has changed. Here's the Activity layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white"
>
<android.support.design.widget.AppBarLayout android:id="#+id/appbar"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:paddingTop="#dimen/appbar_padding_top"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar android:id="#+id/toolbar"
android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" app:popupTheme="#style/AppTheme.PopupOverlay"
app:layout_scrollFlags="scroll|enterAlways">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<me.core.utility.TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textSize="24sp"
android:id="#+id/title_bar"
android:textColor="#android:color/white"
android:text="Edit"
/>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#id/appbar"
android:id="#+id/listview"
android:scrollbars="none"
android:layout_above="#+id/buttons_layout"
android:layout_gravity="center_horizontal|top"
/>
<LinearLayout
android:weightSum="2"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:background="#android:color/transparent"
android:id="#+id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CANCEL"
android:layout_weight="1"
android:layout_margin="#dimen/activity_vertical_margin"
android:id="#+id/cancel_editing_button"
android:background="#drawable/custom_button_logout"
android:textColor="#android:color/white"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DONE"
android:layout_weight="1"
android:layout_margin="#dimen/activity_vertical_margin"
android:id="#+id/done_editing_button"
android:background="#drawable/custom_button_logout"
android:textColor="#android:color/white"
/>
</LinearLayout>
</RelativeLayout>
And here's an image of what this all looks like:
Does anybody have any ideas why this Activity has gone rogue??
EDIT: Added Manifest
<application
tools:replace="android:icon"
android:allowBackup="true"
android:icon="#mipmap/ic_trans2"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"
android:name=".utility.AppInit"
>
<!-- [START gcm_receiver] -->
<receiver
android:name="com.google.android.gms.gcm.GcmReceiver"
android:exported="true"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="software.gcm" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
</receiver>
<!-- [END gcm_receiver] -->
<!-- [START gcm_listener] -->
<service
android:name=".gcm.GcmListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
<!-- [END gcm_listener] -->
<!-- [START instanceID_listener] -->
<service
android:name=".gcm.InstanceIDListenerService"
android:exported="false" >
<intent-filter>
<action android:name="com.google.android.gms.iid.InstanceID" />
</intent-filter>
</service>
<!-- [END instanceID_listener] -->
<!-- [START registration_service] -->
<service
android:name=".gcm.RegistrationIntentService"
android:exported="false" >
</service>
<!-- [END registration_service] -->
<!-- [START application activities] -->
<activity
android:name=".userinterface.MainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".session.InitSessionActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".userinterface.ProfileActivity"
android:label="#string/title_activity_profile"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="me.core.userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.AddBuddyActivity"
android:label="Add Buddy"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.ModifyActivity"
android:label=""
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.BuddyRequestsActivity"
android:label=""
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<activity
android:name=".userinterface.ThreadDetailsActivity"
android:label="#string/title_activity_messages"
android:screenOrientation="portrait"
android:parentActivityName=".userinterface.MainActivity"
android:windowSoftInputMode="stateHidden|adjustResize">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".userinterface.MainActivity" />
</activity>
<!-- [END application activities] -->
</application>
EDIT: Added source
public class ModifyActivity extends AppCompatActivity implements DeleteConfirmationDialog.DeleteConfirmationListener {
private static String LOG_TAG = ModifyActivity.class.getCanonicalName();
private DatabaseHelper databaseHelper;
private BusProvider busProvider;
/** UI references*/
private ProgressDialog progressDialog;
TextView title;
private Obj selectedObj; // The obj to be edited
private ModifyActivityListAdapter modifyActivityListAdapter;
private ArrayList<Buddy> buddiesToAdd; // Buddies to be added
private ArrayList<Buddy> buddiesToRemove; // Buddies to be removed
// Allows these two processes to keep track of one another, and go back to buddies activity when both are done
private boolean additionDone;
private boolean deletionDone;
private boolean actionTaken;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify);
busProvider = BusProvider.getInstance();
databaseHelper = DatabaseHelper.getInstance(getApplicationContext());
title = (TextView)findViewById(R.id.title_bar);
int id = Integer.valueOf(getIntent().getStringExtra(ConstantValues.IntentArguments.ARG_ID));
// The object to be edited
selectedObj = databaseHelper.selectObjWithId(id);
// if (selectedObj!=null) {
// title.setText(selectedObj.getName());
// }
// Get all members of chosen obj
ArrayList<Member> membersOfSelectedObj = databaseHelper.selectMembersOfObj(id);
//Instantiate
ListView editListView = (ListView)findViewById(R.id.edit_listview);
// Create adapter
modifyActivityListAdapter = new ModifyActivityListAdapter(getApplicationContext(), membersOfSelectedObj);
// Attach adapter
editListView.setAdapter(modifyActivityListAdapter);
Button doneButton = (Button)findViewById(R.id.done_editing_button);
Button cancelButton = (Button)findViewById(R.id.cancel_editing_button);
ImageButton deleteButton = (ImageButton)findViewById(R.id.delete_button);
ImageButton renameButton = (ImageButton)findViewById(R.id.rename_button);
doneButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
analyzeUserInput(modifyActivityListAdapter.getAllBuddies());
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
onBackPressed();
}
});
deleteButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createDeleteConfirmDialog();
}
});
renameButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
createRenameConfirmDialog();
}
});
}
EDIT: posting code of the list item, which is the thing that's really discolored. The checkbox should be orange, and font black, but they show up totally invisible (white), so I need to change the text color manually.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:minHeight="?android:attr/listPreferredItemHeight"
tools:context=".userinterface.ModifyActivity"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:text="howdy"
android:textColor="#android:color/black"
android:textSize="20sp"
android:layout_centerVertical="true"
android:id="#+id/edit_list_item_textview"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shadowColor="#color/lb_orange"
android:layout_centerVertical="true"
android:id="#+id/edit_list_item_checkbox"
android:focusable="false"
android:layout_alignParentRight="true"
/>
</RelativeLayout>

It is because of how you construct your ModifyActivityListAdapter. You are giving it an application context, which the adapter uses to inflate its item views. Try passing in the activity context instead.
// Create adapter
modifyActivityListAdapter = new ModifyActivityListAdapter(this, membersOfSelectedObj);
By default, an application context does not hold theme information. As such, views inflated with it will not have your customized theme.
When you specify android:theme in your manifest's <application> element, it is not applied on the Application object, but rather at the activity level. The attribute is just for the convenience of specifying one theme that should be applied to all <activity> elements. You can use Context.setTheme(..) to apply a theme to your application context object, but that is not recommended. Instead, you should use an activity context whenever you work with views.
For more check out Dave Smith's detailed article about the Context class. It's from 2013, but Contexts didn't really change much since then.

On the xml layout file that is being used on setContentView go to the visual design portion and look at the top header in that window. You can set your theme by clicking the button to the left of the activity name tab.

have you checked if its a issue in code, like you might have an issue with view holder design pattern in your listview implementation. As the adapter code has not been posted

Related

How to change the base color of an application

When I launch my application, the screen goes white before displaying my Splash Screen
I would like to remove if possible or put the background the same color as my Splash Screen
But I do not know how, Can someone help me
Thank you
You need to remove your splash screen code as the white screen is itself a splash, provided by android. You just need to change it according to your need.
You first need to create a drawable with name splash_screen.xml and put this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/black"/>
<item
android:drawable="#mipmap/ic_launcher_round"
android:gravity="center"/>
</layer-list>
after that you need to create a activity which launches your MainActivity
Something like this
class OnBoardingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DashboardActivity.launch(this)
finish()
}
}
then you need to overwrite the default splash screen with your styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
after that last step is to add this theme in your manifest.
the activity which launches the app will have this style
<activity
android:name=".ui.onboarding.OnBoardingActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you could use separate activity for your splash screen
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddddd"
tools:context=".SplashScreen">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_icon" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Splash Screen"
android:textSize="25sp" />
Class
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(getApplicationContext(),MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
}, 2000);
}
}
Manifest
( Launch Activity as SplashActivity )
<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/Theme.SplashtoMain">
<activity android:name=".MainActivity"/>
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant)

i am new to Android and i might have a silly / dumb Question. I have got an Activity where i want to dynamically create Multiple Input Fields. The amount of Input Fields is defined by the User.
Because the Input is Styled and Consists of 2 Elements and didnt want to Create these Elements every Time because of Elements have got multiple Parameters that are the same every time. Thats why i created a XML File just for this two Elements which i would like to use in my Programm to Create the Inputs.
View_input.xml
<?xml version="1.0" encoding="utf-8"?>
<merge 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"
android:orientation="vertical"
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout">
<com.google.android.material.textfield.TextInputLayout
android:id="#+id/textInputLayoutTableName"
style="#style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="10dp"
android:hint="#string/create_table_name"
android:inputType="text"
app:boxStrokeColor="#color/colorAccent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:placeholderText="#string/create_table_table_name_placeholder"
app:startIconTintMode="src_in">
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/textInputName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:text="" />
</com.google.android.material.textfield.TextInputLayout>
</merge>
My Target XML (activity_create_table_column_names.xml) looks like this:
<?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=".ui.createtable.CreateTableColumnNamesActivity">
<LinearLayout
android:id="#+id/columnNameInputContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="start"
android:orientation="vertical"
android:padding="20dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/create_table_column_names"
android:textStyle="bold" />
<!-- HERE -->
</LinearLayout>
Where i wrote <!-- HERE -->i want all my Input-Fields to be.
I started with just displaying one Input:
private fun initLayout() {
val container = findViewById<LinearLayout>(R.id.columnNameInputContainer)
val inflater = applicationContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.view_input, LinearLayout(this))
container.addView(view)
}
But i got the Following Exception:
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
at com.google.android.material.internal.ThemeEnforcement.obtainTintedStyledAttributes(ThemeEnforcement.java:115)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:458)
at com.google.android.material.textfield.TextInputLayout.<init>(TextInputLayout.java:417)
My Styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
...
</style>
</resources>
What am i doing wrong? Is this even the correct way i should programm something like this?
Edit:
Android.xml
<?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="de.hsos.ma.adhocdb">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:appComponentFactory="#string/app_name"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:appComponentFactory">
<activity
android:name=".ui.createtable.CreateTableColumnNamesActivity"
android:parentActivityName=".ui.homescreen.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.createtable.CreateTableActivity"
android:parentActivityName=".ui.homescreen.MainActivity" />
<activity
android:name=".ui.homescreen.TestTableActivity"
android:parentActivityName=".ui.homescreen.MainActivity">
<!--
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-->
</activity>
<activity
android:name=".ui.TableShow.TableShowActivity"
android:parentActivityName=".ui.homescreen.MainActivity" />
<activity android:name=".ui.tablelist.LayoutTableListItem" />
<activity android:name=".ui.homescreen.MainActivity">
</activity>
</application>
</manifest>
found the solution ,get your inflator from activity not application just modify your initLayout() like this
// here is the fix
val inflater = getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
just set the theme on the chip itself using android:theme="#style/Theme.MaterialComponents.Bridge:
<com.google.android.material.chip.Chip
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:theme="#style/Theme.MaterialComponents.Bridge"****
style="#style/CustomFiltersChipChoice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipStrokeColor="#F0F"
app:chipStrokeWidth="1dp"
app:textEndPadding="10dp"
app:textStartPadding="10dp"
tools:chipText="my chip"
tools:text="Fortune" />
If you don't want your view to change and with on tool bar try this,
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar.Bridge"/>

When keyboard appears the user can't scroll to the last 4 items in listview using a searchview

I have a listview with items and a searchview in my toolbar. When the user clicks on the search icon the keyboard appears. There's a problem which drives me nuts. When the keyboard appears the user can't scroll to the last four items and yes I tried android:windowSoftInputMode="adjustResize" and android:windowSoftInputMode="adjustPan", but they did nothing.
Manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<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"
android:usesCleartextTraffic="true">
<activity android:name=".Adapter">
</activity>
<activity
android:name=".OnSwipeTouchListener"
android:label="#string/title_activity_on_swipe_touch_listener"
android:theme="#style/AppTheme.NoActionBar" />
<activity
android:name=".Activity2"
android:screenOrientation="sensorLandscape" />
<activity
android:name=".MainActivity"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Activity.xml
<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">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="To get started please click the button below !"
app:layout_constraintBottom_toTopOf="#+id/button"
app:layout_constraintEnd_toEndOf="#+id/mainlistview"
app:layout_constraintHorizontal_bias="0.533"
app:layout_constraintStart_toStartOf="#+id/mainlistview"
app:layout_constraintTop_toTopOf="#+id/mainlistview"
app:layout_constraintVertical_bias="0.626" />
<Button
android:id="#+id/button"
android:layout_width="123dp"
android:layout_height="59dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:text="Open m3u"
app:layout_constraintBottom_toBottomOf="#+id/mainlistview"
app:layout_constraintEnd_toEndOf="#+id/mainlistview"
app:layout_constraintStart_toStartOf="#+id/mainlistview"
app:layout_constraintTop_toTopOf="#+id/mainlistview" />
<ListView
android:id="#+id/mainlistview"
android:layout_width="match_parent"
android:layout_height="673dp"
android:layout_marginTop="2dp"
android:gravity="right"
android:textSize="2dp"
app:layout_constraintTop_toBottomOf="#+id/toolbar"
tools:layout_editor_absoluteX="-144dp">
</ListView><![CDATA[
/>/>
]]>
</androidx.constraintlayout.widget.ConstraintLayout>
I know there are billion questions to this problem, but literally nothing worked !!! Thanks in advance !
Update
Try this:
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Toolbar toolbar = findViewById(R.id.main_toolbar);
setSupportActionBar(toolbar);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.toolbar_menu, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(#NonNull MenuItem item) {
if(item.getItemId() == R.id.action_search) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
res/menu/toolbar_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu>
<item
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/action_search"
android:icon="#android:drawable/ic_menu_search"
app:showAsAction="always"
app:actionViewClass="androidx.appcompat.widget.SearchView"
android:title="#string/search"/>
</menu>
Note: I've populated the list of only 16 items using android:entries attribute
which has value of string-array (inside stars below)
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/main_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
**android:entries="#array/dummy_items"**
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
/>
<com.google.android.material.appbar.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/main_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:theme="#style/Theme.AppCompat" />
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
And styles.xml
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- whatever customization -->
build.gradle(The app one)
...
dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
}
Screenshot
Original answer
I would suggest to implement a SearchDialog Activity.
It shows a pop-up dialog for suggestions and, being a dialog, doesn't go behind the keyboard.
Read this official Android guide for more information.
https://developer.android.com/guide/topics/search/search-dialog#SearchDialog

Splash Screen not properly displayed

Code For splash.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/notice2"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".SplashScreen">
</RelativeLayout>
Code For AndroidManifest.xml :
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity
android:name="com.kksworld.noticeboard.SplashScreen"
android:label="#string/title_activity_splash_screen"
android:theme="#style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kksworld.noticeboard.LoginActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
</activity>
<activity
android:name="com.kksworld.noticeboard.Registration"
android:label="#string/title_activity_registration"
android:theme="#style/AppTheme.NoActionBar" />
</application>
`I am trying to add splash screen in my project. But after running the app the screen stops for the time i have set the timer but exact splash screen is not coming. After that everything is coming. Please Help. Thanks.
Code for Splash Activity :
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_splash_screen);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, LoginActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Try using the bellow code
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="info.androidhive.androidsplashscreentimer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- Splash screen -->
<activity
android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Main activity -->
<activity
android:name="info.androidhive.androidsplashscreentimer.MainActivity"
android:label="#string/app_name" >
</activity>
</application>
</manifest>
activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/gradient_background" >
<ImageView
android:id="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/wwe_logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:textSize="12dp"
android:textColor="#454545"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:text="www.androidhive.info" />
</RelativeLayout>
SplashScreen.java
package info.androidhive.androidsplashscreentimer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreen extends Activity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
/*
* Showing splash screen with a timer. This will be useful when you
* want to show case your app logo / company
*/
#Override
public void run() {
// This method will be executed once the timer is over
// Start your app main activity
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
// close this activity
finish();
}
}, SPLASH_TIME_OUT);
}
}
Splash screens that delay the app should not be used as they interrupt the users in whatever they want to do with your app.
But: There is a way better approach and it is even easier to implement!
Every app needs some time to start and while its starting, most apps only display a white background as this is the default. You can change that however by adding a new style to your themes.xml that sets the windowBackground to any drawable
<style name="YourApp.AppTheme.Splashscreen" parent="YourApplicationsTheme">
<item name="android:windowBackground">#drawable/splashscreen</item>
</style>
You can define the drawable like that if you want a logo on a coloured background:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/some_color"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/some_logo"/>
</item>
</layer-list>
Just add this theme to your <application> in the AndroidManifest.xml and your splash screen is already up and working.
Finally, set your theme back to your normal theme after the startup using
getApplication().setTheme(R.style.YourApplicationsTheme);
to prevent the splash from appearing whenever you switch activities.
All done! A beautiful splash screen without delaying the user.
Android design guidelines are also suggesting that way and you can also see this for reference.
Check your layout files. Make sure you are using the correct layout files. In the java code you have used content_splash_screen.xml, but, you have posted the code for splash.xml.
There are no errors in the code, your code should run fine.

error in running application on android emulator

I have written an app with XML and still I don't write Classes by java code. But the emulator can show my app by its name and after that it says " unfortunately, app has stopped." What I have to do for this problem??!
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Textview
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/TextView2"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Button"
/>
</LinearLayout>
You must have at least one activity (Java class) in your application so that manifest.xml could recognize that and run it.
You have to use an activity to show this xml :
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
As you can see your xml is called by the setContentView method.
This activity must be declared in your AndroidManifest.xml with
<activity
android:name="YOURPACKAGE.ACTIVITY_NAME"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Categories

Resources